diff --git a/nacl.go b/nacl.go index 6ee74d8..48325b8 100644 --- a/nacl.go +++ b/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) +}