nats

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EdgeConnect

func EdgeConnect(o 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 ListenForCmd

func ListenForCmd(nc *nats.Conn, deviceID string, callback func(cmd data.NodeCmd)) error

ListenForCmd listens for a file sent from server

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 SendCmd

func SendCmd(nc *nats.Conn, cmd data.NodeCmd, timeout time.Duration) error

SendCmd sends a command to device via NATS

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.

Types

type EdgeOptions

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

EdgeOptions describes options for connecting edge devices

Jump to

Keyboard shortcuts

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