+7
@@ -52,10 +52,17 @@ func connectToNatsJetStream(options Options) (nats.JetStreamContext, error) {
|
||||
nopts.Secure = true
|
||||
nopts.TLSConfig = options.TLSConfig
|
||||
}
|
||||
if options.NkeyConfig != "" {
|
||||
nopts.Nkey = options.NkeyConfig
|
||||
}
|
||||
|
||||
if len(options.Address) > 0 {
|
||||
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)
|
||||
|
||||
+16
@@ -11,9 +11,11 @@ type Options struct {
|
||||
ClusterID string
|
||||
ClientID string
|
||||
Address string
|
||||
NkeyConfig string
|
||||
TLSConfig *tls.Config
|
||||
Logger logger.Logger
|
||||
SyncPublish bool
|
||||
Name string
|
||||
}
|
||||
|
||||
// Option is a function which configures options.
|
||||
@@ -47,6 +49,13 @@ func TLSConfig(t *tls.Config) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Nkey string to use when connecting to the cluster.
|
||||
func NkeyConfig(nkey string) Option {
|
||||
return func(o *Options) {
|
||||
o.NkeyConfig = nkey
|
||||
}
|
||||
}
|
||||
|
||||
// Logger sets the underlyin logger
|
||||
func Logger(log logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
@@ -60,3 +69,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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user