diff --git a/v4/events/natsjs/nats.go b/v4/events/natsjs/nats.go index f8b64c94..5d14e227 100644 --- a/v4/events/natsjs/nats.go +++ b/v4/events/natsjs/nats.go @@ -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) diff --git a/v4/events/natsjs/options.go b/v4/events/natsjs/options.go index fdecd87a..0859264d 100644 --- a/v4/events/natsjs/options.go +++ b/v4/events/natsjs/options.go @@ -14,6 +14,7 @@ type Options struct { TLSConfig *tls.Config Logger logger.Logger SyncPublish bool + Name string } // Option is a function which configures options. @@ -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 + } +}