Skip to content

Commit

Permalink
Merge pull request #122 from kobergj/AllowNamingNatsConnections
Browse files Browse the repository at this point in the history
Allow naming nats connections
  • Loading branch information
jochumdev authored Aug 7, 2023
2 parents 75ebf5c + cadcc16 commit f31dcd2
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 f31dcd2

Please sign in to comment.