nats

package
v0.0.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package nats contains utilties for reading/writing data using NATS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeEdgePointsMsg added in v0.0.30

func DecodeEdgePointsMsg(msg *natsgo.Msg) (string, string, []data.Point, error)

DecodeEdgePointsMsg decodes NATS message into node ID and points

func DecodeNodePointsMsg added in v0.0.23

func DecodeNodePointsMsg(msg *natsgo.Msg) (string, []data.Point, error)

DecodeNodePointsMsg decodes NATS message into node ID and points

func Dump added in v0.0.23

func Dump(nc *natsgo.Conn, msg *natsgo.Msg) error

Dump converts displays a NATS message

func EdgeConnect

func EdgeConnect(eo EdgeOptions) (*nats.Conn, error)

EdgeConnect is a function that attempts connections for edge devices with appropriate timeouts, backups, etc. Currently set to disconnect if we don't have a connection after 6m, and then exp backup to try to connect every 6m after that.

func ExpBackoff

func ExpBackoff(attempts int, max time.Duration) time.Duration

ExpBackoff calculates an exponential time backup to max duration + a random fraction of 1s

func GetNode added in v0.0.30

func GetNode(nc *natsgo.Conn, id, parent string) (data.NodeEdge, error)

GetNode over NATS. If id is "root", the root node is fetched. If parent is set to "skip", the edge details are not included and the hash is calculated without the edge points. returns data.ErrDocumentNotFound if node is not found.

func GetNodeChildren added in v0.0.30

func GetNodeChildren(nc *natsgo.Conn, id, typ string, includeDel bool) ([]data.NodeEdge, error)

GetNodeChildren over NATS (immediate children only, not recursive) deleted nodes are skipped unless includeDel is set to true. typ can be used to limit nodes to a particular type, otherwise, all nodes are returned.

func ListenForFile

func ListenForFile(nc *nats.Conn, dir, deviceID string, callback func(path string)) error

ListenForFile listens for a file sent from server. dir is the directly to place downloaded files.

func SendEdgePoint added in v0.0.30

func SendEdgePoint(nc *natsgo.Conn, nodeID, parentID string, point data.Point, ack bool) error

SendEdgePoint sends a edge point using the nats protocol

func SendEdgePoints added in v0.0.30

func SendEdgePoints(nc *natsgo.Conn, nodeID, parentID string, points data.Points, ack bool) error

SendEdgePoints sends points using the nats protocol

func SendFile

func SendFile(nc *nats.Conn, deviceID string, reader io.Reader, name string, callback func(int)) error

SendFile can be used to send a file to a device. Callback provides bytes transfered.

func SendNode added in v0.0.30

func SendNode(src, dest *natsgo.Conn, node data.NodeEdge) error

SendNode is used to recursively send a node and children over nats

func SendNodePoint added in v0.0.30

func SendNodePoint(nc *natsgo.Conn, nodeID string, point data.Point, ack bool) error

SendNodePoint sends a node point using the nats protocol

func SendNodePointCreate added in v0.0.30

func SendNodePointCreate(nc *natsgo.Conn, nodeID string, point data.Point, ack bool) error

SendNodePointCreate sends a node point using the nats protocol and creates the node if it does not already exist

func SendNodePoints added in v0.0.30

func SendNodePoints(nc *natsgo.Conn, nodeID string, points data.Points, ack bool) error

SendNodePoints sends node points using the nats protocol

func SendNodePointsCreate added in v0.0.30

func SendNodePointsCreate(nc *natsgo.Conn, nodeID string, points data.Points, ack bool) error

SendNodePointsCreate sends a node point using the nats protocol and creates the node if it does not already exist

func String added in v0.0.23

func String(nc *natsgo.Conn, msg *natsgo.Msg) (string, error)

String converts a NATS message to a string

func SubjectEdgeAllPoints added in v0.0.30

func SubjectEdgeAllPoints() string

SubjectEdgeAllPoints provides subject for all edge points for any node

func SubjectEdgePoints added in v0.0.30

func SubjectEdgePoints(nodeID, parentID string) string

SubjectEdgePoints constructs a NATS subject for edge points

func SubjectNodeAllPoints added in v0.0.30

func SubjectNodeAllPoints() string

SubjectNodeAllPoints provides subject for all points for any node

func SubjectNodePoints added in v0.0.30

func SubjectNodePoints(nodeID string) string

SubjectNodePoints constructs a NATS subject for node points

Types

type EdgeOptions

type EdgeOptions struct {
	Server       string
	AuthToken    string
	NoEcho       bool
	Disconnected func()
	Reconnected  func()
	Closed       func()
}

EdgeOptions describes options for connecting edge devices

type Metric added in v0.0.34

type Metric struct {
	// contains filtered or unexported fields
}

Metric is a type that can be used to track metrics and periodically report them to a node point. Data is queued and averaged and then the average is sent out as a point.

func NewMetric added in v0.0.34

func NewMetric(nc *natsgo.Conn, nodeID, pointType string, reportPeriod time.Duration) *Metric

NewMetric creates a new metric

func (*Metric) AddSample added in v0.0.34

func (m *Metric) AddSample(s float64) error

AddSample adds a sample and reports it if reportPeriod has expired

func (*Metric) SetNodeID added in v0.0.34

func (m *Metric) SetNodeID(id string)

SetNodeID -- this is a bit of a hack to get around some init issues

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL