gobot: gobot.io/x/gobot/platforms/nats Index | Files

package nats

import "gobot.io/x/gobot/platforms/nats"

Package nats provides Gobot adaptor for the nats message service. Installing:

go get gobot.io/x/gobot/platforms/nats

For further information refer to nats README: https://github.com/hybridgroup/gobot/blob/master/platforms/nats/README.md


Package Files

doc.go nats_adaptor.go nats_driver.go


const (
    // Data event when data is available for Driver
    Data = "data"

    // Error event when error occurs in Driver
    Error = "error"

type Adaptor Uses

type Adaptor struct {
    Host string
    // contains filtered or unexported fields

Adaptor is a configuration struct for interacting with a NATS server. Name is a logical name for the adaptor/nats server connection. Host is in the form "localhost:4222" which is the hostname/ip and port of the nats server. ClientID is a unique identifier integer that specifies the identity of the client.

func NewAdaptor Uses

func NewAdaptor(host string, clientID int, options ...nats.Option) *Adaptor

NewAdaptor populates a new NATS Adaptor.

func NewAdaptorWithAuth Uses

func NewAdaptorWithAuth(host string, clientID int, username string, password string, options ...nats.Option) *Adaptor

NewAdaptorWithAuth populates a NATS Adaptor including username and password.

func (*Adaptor) Connect Uses

func (a *Adaptor) Connect() (err error)

Connect makes a connection to the Nats server.

func (*Adaptor) Disconnect Uses

func (a *Adaptor) Disconnect() (err error)

Disconnect from the nats server.

func (*Adaptor) Finalize Uses

func (a *Adaptor) Finalize() (err error)

Finalize is simply a helper method for the disconnect.

func (*Adaptor) Name Uses

func (a *Adaptor) Name() string

Name returns the logical client name.

func (*Adaptor) On Uses

func (a *Adaptor) On(event string, f func(msg Message)) bool

On is an event-handler style subscriber to a particular topic (named event). Supply a handler function to use the bytes returned by the server.

func (*Adaptor) Publish Uses

func (a *Adaptor) Publish(topic string, message []byte) bool

Publish sends a message with the particular topic to the nats server.

func (*Adaptor) SetName Uses

func (a *Adaptor) SetName(n string)

SetName sets the logical client name.

type Driver Uses

type Driver struct {
    // contains filtered or unexported fields

Driver for NATS

func NewDriver Uses

func NewDriver(a *Adaptor, topic string) *Driver

NewDriver returns a new Gobot NATS Driver

func (*Driver) Connection Uses

func (m *Driver) Connection() gobot.Connection

Connection returns Connections used by the Driver

func (*Driver) Halt Uses

func (m *Driver) Halt() error

Halt halts the Driver

func (*Driver) Name Uses

func (m *Driver) Name() string

Name returns name for the Driver

func (*Driver) On Uses

func (m *Driver) On(n string, f func(msg Message)) error

On subscribes to data updates for the current device topic, and then calls the message handler function when data is received

func (*Driver) Publish Uses

func (m *Driver) Publish(data interface{}) bool

Publish a message to the current device topic

func (*Driver) SetName Uses

func (m *Driver) SetName(name string)

SetName sets name for the Driver

func (*Driver) SetTopic Uses

func (m *Driver) SetTopic(topic string)

SetTopic sets the current topic for the Driver

func (*Driver) Start Uses

func (m *Driver) Start() error

Start starts the Driver

func (*Driver) Topic Uses

func (m *Driver) Topic() string

Topic returns the current topic for the Driver

type Message Uses

type Message *nats.Msg

Message is a message received from the server.

Package nats imports 4 packages (graph) and is imported by 1 packages. Updated 2019-10-16. Refresh now. Tools for package owners.