fix: add SetupJetStream()
This commit is contained in:
parent
e8cba551c7
commit
5cf7a062b9
19
nacl.go
19
nacl.go
@ -12,6 +12,7 @@ import (
|
||||
var (
|
||||
NatsClient *nats.Conn
|
||||
StanClient stan.Conn
|
||||
JsClient nats.JetStreamContext
|
||||
natsLock = sync.Mutex{}
|
||||
stanLock = sync.Mutex{}
|
||||
)
|
||||
@ -40,6 +41,20 @@ func SetupNatsWithCreds(host string, port int, credsFile string, closeHandler *g
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetupJetStream(host string, port int, credsFile string, closeHandler *grawt.CloseHandler, opts ...nats.JSOpt) error {
|
||||
var err error
|
||||
if err := SetupNatsWithCreds(host, port, credsFile, closeHandler); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
JsClient, err = NatsClient.JetStream(opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot init JS: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetupNats(host string, port int, user string, pass string, closeHandler *grawt.CloseHandler) error {
|
||||
natsLock.Lock()
|
||||
defer natsLock.Unlock()
|
||||
@ -128,3 +143,7 @@ func FinalizeNats(subscriptions *[]*nats.Subscription) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func FinalizeJetStream(subscriptions *[]*nats.Subscription) error {
|
||||
return FinalizeNats(subscriptions)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user