Skip to content

Commit d72f3aa

Browse files
committed
eventbus/nats: never give up trying to reconnect
1 parent dbabe66 commit d72f3aa

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

resource-aggregate/cqrs/eventbus/nats/publisher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewPublisher(config Config, opts ...Option) (*Publisher, error) {
3636

3737
// NewPublisher creates a publisher.
3838
func newPublisher(url string, eventMarshaler MarshalerFunc, options ...nats.Option) (*Publisher, error) {
39+
options = append(options, nats.MaxReconnects(-1))
3940
conn, err := nats.Connect(url, options...)
4041
if err != nil {
4142
return nil, fmt.Errorf("cannot connect to server: %w", err)

resource-aggregate/cqrs/eventbus/nats/subscriber.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func newSubscriber(url string, eventUnmarshaler UnmarshalerFunc, goroutinePoolGo
5858
return nil, fmt.Errorf("invalid errFunc")
5959
}
6060

61+
options = append(options, nats.MaxReconnects(-1))
6162
conn, err := nats.Connect(url, options...)
6263
if err != nil {
6364
return nil, fmt.Errorf("cannot create client: %w", err)

0 commit comments

Comments
 (0)