update nats and add some debug callbacks
This commit is contained in:
4
go.mod
4
go.mod
@@ -6,8 +6,8 @@ require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.5
|
||||
github.com/lib/pq v1.10.7
|
||||
github.com/nats-io/nats-server/v2 v2.9.8 // indirect
|
||||
github.com/nats-io/nats.go v1.20.0
|
||||
github.com/nats-io/nats-server/v2 v2.9.10 // indirect
|
||||
github.com/nats-io/nats.go v1.22.0
|
||||
github.com/ugorji/go/codec v1.2.7
|
||||
github.com/wh1te909/trmm-shared v0.0.0-20220227075846-f9f757361139
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
|
8
go.sum
8
go.sum
@@ -17,10 +17,10 @@ github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRU
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
|
||||
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
|
||||
github.com/nats-io/nats-server/v2 v2.9.8 h1:jgxZsv+A3Reb3MgwxaINcNq/za8xZInKhDg9Q0cGN1o=
|
||||
github.com/nats-io/nats-server/v2 v2.9.8/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g=
|
||||
github.com/nats-io/nats.go v1.20.0 h1:T8JJnQfVSdh1CzGiwAOv5hEobYCBho/0EupGznYw0oM=
|
||||
github.com/nats-io/nats.go v1.20.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
|
||||
github.com/nats-io/nats-server/v2 v2.9.10 h1:LMC46Oi9E6BUx/xBsaCVZgofliAqKQzRPU6eKWkN8jE=
|
||||
github.com/nats-io/nats-server/v2 v2.9.10/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g=
|
||||
github.com/nats-io/nats.go v1.22.0 h1:3dxyVf+S449DbMriqQV27HgSbXklxT9SUKbDKIxhrV0=
|
||||
github.com/nats-io/nats.go v1.22.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
|
||||
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
|
||||
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
|
||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
|
2
main.go
2
main.go
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
version = "3.3.3"
|
||||
version = "3.4.0"
|
||||
log = logrus.New()
|
||||
)
|
||||
|
||||
|
@@ -20,7 +20,27 @@ func Svc(logger *logrus.Logger, cfg string) {
|
||||
logger.Fatalln(err)
|
||||
}
|
||||
|
||||
opts := setupNatsOptions(r.Key)
|
||||
opts := []nats.Option{
|
||||
nats.Name("trmm-nats-api"),
|
||||
nats.UserInfo("tacticalrmm", r.Key),
|
||||
nats.ReconnectWait(time.Second * 2),
|
||||
nats.RetryOnFailedConnect(true),
|
||||
nats.IgnoreAuthErrorAbort(),
|
||||
nats.MaxReconnects(-1),
|
||||
nats.ReconnectBufSize(-1),
|
||||
nats.DisconnectErrHandler(func(nc *nats.Conn, nerr error) {
|
||||
logger.Debugln("NATS disconnected:", nerr)
|
||||
logger.Debugf("%+v\n", nc.Statistics)
|
||||
}),
|
||||
nats.ReconnectHandler(func(nc *nats.Conn) {
|
||||
logger.Debugln("NATS reconnected")
|
||||
logger.Debugf("%+v\n", nc.Statistics)
|
||||
}),
|
||||
nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, nerr error) {
|
||||
logger.Errorln("NATS error:", nerr)
|
||||
logger.Errorf("%+v\n", sub)
|
||||
}),
|
||||
}
|
||||
nc, err := nats.Connect(r.NatsURL, opts...)
|
||||
if err != nil {
|
||||
logger.Fatalln(err)
|
||||
|
@@ -5,26 +5,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
nats "github.com/nats-io/nats.go"
|
||||
trmm "github.com/wh1te909/trmm-shared"
|
||||
)
|
||||
|
||||
func setupNatsOptions(key string) []nats.Option {
|
||||
opts := []nats.Option{
|
||||
nats.Name("trmm-nats-api"),
|
||||
nats.UserInfo("tacticalrmm", key),
|
||||
nats.ReconnectWait(time.Second * 2),
|
||||
nats.RetryOnFailedConnect(true),
|
||||
nats.MaxReconnects(-1),
|
||||
nats.ReconnectBufSize(-1),
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
func GetConfig(cfg string) (db *sqlx.DB, r DjangoConfig, err error) {
|
||||
if cfg == "" {
|
||||
cfg = "/rmm/api/tacticalrmm/nats-api.conf"
|
||||
|
Reference in New Issue
Block a user