Skip to content

Commit 53adf7f

Browse files
authored
update events for ephemeral consumer support (#92)
Signed-off-by: Matt Siwiec <[email protected]>
1 parent f3a53ea commit 53adf7f

File tree

3 files changed

+30
-540
lines changed

3 files changed

+30
-540
lines changed

cmd/run.go

+4-26
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package cmd
33
import (
44
"context"
55
"errors"
6-
"fmt"
7-
"math/rand"
86
"os"
97
"os/signal"
108
"syscall"
@@ -127,16 +125,15 @@ func run(cmdCtx context.Context, v *viper.Viper) error {
127125
mgr.LBClient = lbapi.NewClient(viper.GetString("loadbalancerapi.url"))
128126
}
129127

130-
// generate a random queuegroup name
131-
// this is to prevent multiple instances of this service from receiving the same message
132-
// and processing it
133-
config.AppConfig.Events.NATS.QueueGroup = generateQueueGroupName()
134-
135128
events, err := events.NewConnection(config.AppConfig.Events, events.WithLogger(logger))
136129
if err != nil {
137130
logger.Fatalw("failed to create events connection", "error", err)
138131
}
139132

133+
defer func() {
134+
_ = events.Shutdown(ctx)
135+
}()
136+
140137
// init events subscriber
141138
subscriber := pubsub.NewSubscriber(
142139
ctx,
@@ -155,10 +152,6 @@ func run(cmdCtx context.Context, v *viper.Viper) error {
155152
}
156153
}
157154

158-
defer func() {
159-
_ = events.Shutdown(ctx)
160-
}()
161-
162155
if err := mgr.Run(); err != nil {
163156
logger.Fatalw("failed starting manager", "error", err)
164157
}
@@ -192,18 +185,3 @@ func validateMandatoryFlags() error {
192185

193186
return errors.Join(errs...) //nolint:goerr113
194187
}
195-
196-
// generateQueueGroupName generates a random queue group name with prefix lbmanager-haproxy-
197-
func generateQueueGroupName() string {
198-
const rlen = 10
199-
200-
alphaNum := []rune("abcdefghijklmnopqrstuvwxyz1234567890")
201-
r := rand.New(rand.NewSource(time.Now().UnixNano()))
202-
b := make([]rune, rlen)
203-
204-
for i := range b {
205-
b[i] = alphaNum[r.Intn(len(alphaNum))]
206-
}
207-
208-
return fmt.Sprintf("lbmanager-haproxy-%s-", string(b))
209-
}

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/spf13/viper v1.18.2
1212
github.com/stretchr/testify v1.8.4
1313
go.infratographer.com/load-balancer-api v0.1.3
14-
go.infratographer.com/x v0.3.9
14+
go.infratographer.com/x v0.3.10-0.20240122202348-a5142b682ef6
1515
go.uber.org/zap v1.26.0
1616
)
1717

@@ -27,7 +27,6 @@ require (
2727
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
2828
github.com/golang-jwt/jwt/v5 v5.1.0 // indirect
2929
github.com/golang/protobuf v1.5.3 // indirect
30-
github.com/google/go-cmp v0.6.0 // indirect
3130
github.com/google/renameio v1.0.1 // indirect
3231
github.com/google/uuid v1.4.0 // indirect
3332
github.com/haproxytech/go-logger v1.1.0 // indirect
@@ -67,7 +66,7 @@ require (
6766
go.opentelemetry.io/otel/metric v1.21.0 // indirect
6867
go.opentelemetry.io/otel/trace v1.21.0 // indirect
6968
go.uber.org/multierr v1.11.0 // indirect
70-
golang.org/x/crypto v0.16.0 // indirect
69+
golang.org/x/crypto v0.17.0 // indirect
7170
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
7271
golang.org/x/net v0.19.0 // indirect
7372
golang.org/x/oauth2 v0.15.0 // indirect

0 commit comments

Comments
 (0)