1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00

28 lines
464 B
Go
Raw Normal View History

// Package nats contains NATS-specific message repository implementation.
package nats
import (
"encoding/json"
"github.com/mainflux/mainflux/writer"
broker "github.com/nats-io/go-nats"
)
const topic string = "msg.coap"
// Stored NATS connection
var snc *broker.Conn
func StoreConnection(nc *broker.Conn) {
snc = nc
}
func Send(msg writer.RawMessage) error {
b, err := json.Marshal(msg)
if err != nil {
return err
}
return snc.Publish(topic, b)
}