Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
QuanTT0110 | ef52e7b820 | |
QuanTT0110 | ca6f37ad8d | |
QuanTT0110 | 36dba4d5d9 | |
QuanTT0110 | bfbd21d579 |
10
constant.go
10
constant.go
|
@ -1,13 +1,15 @@
|
|||
package natsio
|
||||
|
||||
var AllStreams = struct {
|
||||
ChangeStream string
|
||||
MongoCDC string
|
||||
Export string
|
||||
}{
|
||||
ChangeStream: "change_stream",
|
||||
MongoCDC: "mongo_cdc",
|
||||
Export: "export",
|
||||
}
|
||||
|
||||
var AllServers = struct {
|
||||
MongoCDC string
|
||||
Main string
|
||||
}{
|
||||
MongoCDC: "mongo_cdc",
|
||||
Main: "main",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
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)
|
||||
}
|
Loading…
Reference in New Issue