bump: packages; feat: remove STAN (nats-streaming)
This commit is contained in:
44
nacl.go
44
nacl.go
@@ -4,16 +4,13 @@ import (
|
||||
"fmt"
|
||||
"github.com/jar3b/grawt"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/stan.go"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
NatsClient *nats.Conn
|
||||
StanClient stan.Conn
|
||||
natsLock = sync.Mutex{}
|
||||
stanLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
func SetupNatsWithCreds(host string, port int, credsFile string, closeHandler *grawt.CloseHandler) error {
|
||||
@@ -70,47 +67,6 @@ func SetupNats(host string, port int, user string, pass string, closeHandler *gr
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetupStan(clusterName string, clientId string, host string, port int, user string, pass string, closeHandler *grawt.CloseHandler) (err error) {
|
||||
stanLock.Lock()
|
||||
defer stanLock.Unlock()
|
||||
|
||||
if err = SetupNats(host, port, user, pass, closeHandler); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// stan connection
|
||||
StanClient, err = stan.Connect(
|
||||
clusterName,
|
||||
clientId,
|
||||
stan.NatsConn(NatsClient),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot connect to STAN: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func FinalizeStan(subscriptions *[]stan.Subscription) error {
|
||||
stanLock.Lock()
|
||||
defer stanLock.Unlock()
|
||||
if StanClient == nil {
|
||||
return fmt.Errorf("stan client is not initialized")
|
||||
}
|
||||
|
||||
if subscriptions != nil {
|
||||
for _, subscription := range *subscriptions {
|
||||
_ = subscription.Unsubscribe()
|
||||
}
|
||||
}
|
||||
|
||||
if err := StanClient.Close(); err != nil {
|
||||
return fmt.Errorf("cannot disconnect from STAN")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func FinalizeNats(subscriptions *[]*nats.Subscription) error {
|
||||
natsLock.Lock()
|
||||
defer natsLock.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user