Compare commits

..

1 Commits

Author SHA1 Message Date
sinhluu 222ebb90c5 Merge pull request 'develop' (#1) from develop into master
Reviewed-on: #1
2023-04-27 06:56:05 +00:00
2 changed files with 4 additions and 50 deletions

View File

@ -1,15 +1,13 @@
package natsio
var AllStreams = struct {
MongoCDC string
Export string
ChangeStream string
}{
MongoCDC: "mongo_cdc",
Export: "export",
ChangeStream: "change_stream",
}
var AllServers = struct {
Main string
MongoCDC string
}{
Main: "main",
MongoCDC: "mongo_cdc",
}

View File

@ -1,44 +0,0 @@
package natsio
import (
"log"
"github.com/nats-io/nats.go"
)
// JSONEncoder ...
type JSONEncoder struct {
encConn *nats.EncodedConn
}
// Subscribe ...
func (e JSONEncoder) Subscribe(subject string, cb nats.Handler) (*nats.Subscription, error) {
sub, err := e.encConn.Subscribe(subject, cb)
if err != nil {
log.Printf("natsio.JSONEncoder.Subscribe err: %v\n", err)
} else {
log.Printf("natsio.JSONEncoder - subscribed to subject %s successfully\n", subject)
}
return sub, err
}
// QueueSubscribe ...
func (e JSONEncoder) QueueSubscribe(subject, queue string, cb nats.Handler) (*nats.Subscription, error) {
sub, err := e.encConn.QueueSubscribe(subject, queue, cb)
if err != nil {
log.Printf("natsio.JSONEncoder.QueueSubscribe err: %v\n", err)
} else {
log.Printf("natsio.JSONEncoder.QueueSubscribe - subscribed to subject %s successfully\n", subject)
}
return sub, err
}
// Publish ...
func (e JSONEncoder) Publish(reply string, data interface{}) error {
return e.encConn.Publish(reply, data)
}
// Request ...
func (e JSONEncoder) Request(subject string, data interface{}, res interface{}) error {
return e.encConn.Request(subject, data, res, requestTimeout)
}