Skip to content

Commit

Permalink
allow naming nats connections
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Aug 3, 2023
1 parent 1ada012 commit cadcc16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions v4/events/natsjs/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func connectToNatsJetStream(options Options) (nats.JetStreamContext, error) {
nopts.Servers = strings.Split(options.Address, ",")
}

if options.Name != "" {
nopts.Name = options.Name
}
conn, err := nopts.Connect()
if err != nil {
return nil, fmt.Errorf("error connecting to nats at %v with tls enabled (%v): %v", options.Address, nopts.TLSConfig != nil, err)
Expand Down
8 changes: 8 additions & 0 deletions v4/events/natsjs/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Options struct {
TLSConfig *tls.Config
Logger logger.Logger
SyncPublish bool
Name string
}

// Option is a function which configures options.
Expand Down Expand Up @@ -60,3 +61,10 @@ func SynchronousPublish(sync bool) Option {
o.SyncPublish = sync
}
}

// Name allows to add a name to the natsjs connection
func Name(name string) Option {
return func(o *Options) {
o.Name = name
}
}

0 comments on commit cadcc16

Please sign in to comment.