mqtt

package
v0.0.0-...-ee1c4a9 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// QoS_ZERO specifies "at most once"
	QoS_ZERO = byte(0)
	// QoS_ONE specifies "at least once"
	QoS_ONE = byte(1)
	// QoS_TWO specifies "exactly once"
	QoS_TWO = byte(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector struct {
	C MQTT.Client
	// contains filtered or unexported fields
}

func New

func New(host string) *Connector

func (*Connector) AddBroker

func (c *Connector) AddBroker(server string) *Connector

AddBroker adds a broker URI to the list of brokers to be used. The format should be scheme://host:port Where "scheme" is one of "tcp", "ssl", or "ws", "host" is the ip-address (or hostname) and "port" is the port on which the broker is accepting connections.

Default values for hostname is "127.0.0.1", for schema is "tcp://".

An example broker URI would look like: tcp://foobar.com:1883

func (*Connector) Close

func (c *Connector) Close() error

func (*Connector) Connect

func (c *Connector) Connect() error

Connect returns true if connection to mqtt is established

func (*Connector) Dial

func (c *Connector) Dial() error

Dial stablish a connection with the broker and make it usable

func (*Connector) Disconnect

func (c *Connector) Disconnect()

Disconnect returns true if connection to mqtt is closed

func (*Connector) ID

func (c *Connector) ID() string

ID returns the client ID

func (*Connector) Listen

func (c *Connector) Listen(opts *connectors.SubscribeOptions, ch chan []byte) error

func (*Connector) Name

func (c *Connector) Name() string

func (*Connector) On

func (c *Connector) On(opts *connectors.SubscribeOptions, f func([]byte)) error

func (c *Connector) On(opts interface{}, f func(c *MQTT.Client, msg MQTT.Message)) error {

func (*Connector) Put

func (c *Connector) Put(opts *connectors.PublishOptions, msg []byte) error

func (*Connector) SetAutoReconnect

func (c *Connector) SetAutoReconnect(a bool) *Connector

SetAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the ConnectionLostHandler is still called

func (*Connector) SetBinaryWill

func (c *Connector) SetBinaryWill(topic string, payload []byte, qos byte, retained bool) *Connector

SetBinaryWill accepts a []byte will message to be set. When the client connects, it will give this will message to the broker, which will then publish the provided payload (the will) to any clients that are subscribed to the provided topic.

func (*Connector) SetCleanSession

func (c *Connector) SetCleanSession(clean bool) *Connector

SetCleanSession will set the "clean session" flag in the connect message when this client connects to an MQTT broker. By setting this flag, you are indicating that no messages saved by the broker for this client should be delivered. Any messages that were going to be sent by this client before diconnecting previously but didn't will not be sent upon connecting to the broker.

Should be false if reconnect is enabled. Otherwise all subscriptions will be lost

func (*Connector) SetClientID

func (c *Connector) SetClientID(id string) *Connector

SetClientID will set the client id to be used by this client when connecting to the MQTT broker. According to the MQTT v3.1 specification, a client id mus be no longer than 23 characters.

func (*Connector) SetConnectTimeout

func (c *Connector) SetConnectTimeout(t time.Duration) *Connector

SetConnectTimeout limits how long the client will wait when trying to open a connection to an MQTT server before timeing out and erroring the attempt. A duration of 0 never times out. Default 30 seconds. Currently only operational on TCP/TLS connections.

func (*Connector) SetConnectionLostHandler

func (c *Connector) SetConnectionLostHandler(onLost MQTT.ConnectionLostHandler) *Connector

SetConnectionLostHandler will set the OnConnectionLost callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker.

func (*Connector) SetDefaultPublishHandler

func (c *Connector) SetDefaultPublishHandler(defaultHandler MQTT.MessageHandler) *Connector

SetDefaultPublishHandler sets the MessageHandler that will be called when a message is received that does not match any known subscriptions.

func (*Connector) SetDefaultPublishOptions

func (c *Connector) SetDefaultPublishOptions(opts *connectors.PublishOptions) *Connector

func (*Connector) SetDefaultSubscribeOptions

func (c *Connector) SetDefaultSubscribeOptions(opts *connectors.SubscribeOptions) *Connector

func (*Connector) SetHTTPHeaders

func (c *Connector) SetHTTPHeaders(h http.Header) *Connector

SetHTTPHeaders sets the additional HTTP headers that will be sent in the WebSocket opening handshake.

func (*Connector) SetKeepAlive

func (c *Connector) SetKeepAlive(k time.Duration) *Connector

SetKeepAlive will set the amount of time (in seconds) that the client should wait before sending a PING request to the broker. This will allow the client to know that a connection has not been lost with the server.

func (*Connector) SetMaxReconnectInterval

func (c *Connector) SetMaxReconnectInterval(t time.Duration) *Connector

SetMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts when connection is lost

func (*Connector) SetMessageChannelDepth

func (c *Connector) SetMessageChannelDepth(s uint) *Connector

SetMessageChannelDepth sets the size of the internal queue that holds messages while the client is temporairily offline, allowing the application to publish when the client is reconnecting. This setting is only valid if AutoReconnect is set to true, it is otherwise ignored.

func (*Connector) SetOnConnectHandler

func (c *Connector) SetOnConnectHandler(onConn MQTT.OnConnectHandler) *Connector

SetOnConnectHandler sets the function to be called when the client is connected. Both at initial connection time and upon automatic reconnect.

func (*Connector) SetOrderMatters

func (c *Connector) SetOrderMatters(order bool) *Connector

SetOrderMatters will set the message routing to guarantee order within each QoS level. By default, this value is true. If set to false, this flag indicates that messages can be delivered asynchronously from the client to the application and possibly arrive out of order.

func (*Connector) SetPassword

func (c *Connector) SetPassword(p string) *Connector

SetPassword will set the password to be used by this client when connecting to the MQTT broker. Note: without the use of SSL/TLS, this information will be sent in plaintext accross the wire.

func (*Connector) SetPingTimeout

func (c *Connector) SetPingTimeout(k time.Duration) *Connector

SetPingTimeout will set the amount of time (in seconds) that the client will wait after sending a PING request to the broker, before deciding that the connection has been lost. Default is 10 seconds.

func (*Connector) SetProtocolVersion

func (c *Connector) SetProtocolVersion(pv uint) *Connector

SetProtocolVersion sets the MQTT version to be used to connect to the broker. Legitimate values are currently 3 - MQTT 3.1 or 4 - MQTT 3.1.1

func (*Connector) SetResumeSubs

func (c *Connector) SetResumeSubs(resume bool) *Connector

SetResumeSubs will enable resuming of stored (un)subscribe messages when connecting but not reconnecting if CleanSession is false. Otherwise these messages are discarded.

func (*Connector) SetStore

func (c *Connector) SetStore(s MQTT.Store) *Connector

SetStore will set the implementation of the Store interface used to provide message persistence in cases where QoS levels QoS_ONE or QoS_TWO are used. If no store is provided, then the client will use MemoryStore by default.

func (*Connector) SetTLSConfig

func (c *Connector) SetTLSConfig(t *tls.Config) *Connector

SetTLSConfig will set an SSL/TLS configuration to be used when connecting to an MQTT broker. Please read the official Go documentation for more information.

func (*Connector) SetUsername

func (c *Connector) SetUsername(u string) *Connector

SetUsername will set the username to be used by this client when connecting to the MQTT broker. Note: without the use of SSL/TLS, this information will be sent in plaintext accross the wire.

func (*Connector) SetWill

func (c *Connector) SetWill(topic string, payload string, qos byte, retained bool) *Connector

SetWill accepts a string will message to be set. When the client connects, it will give this will message to the broker, which will then publish the provided payload (the will) to any clients that are subscribed to the provided topic.

func (*Connector) SetWriteTimeout

func (c *Connector) SetWriteTimeout(t time.Duration) *Connector

SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a timeout error. A duration of 0 never times out. Default 30 seconds

func (*Connector) Stream

func (c *Connector) Stream(opts *connectors.PublishOptions, ch chan []byte) error

func (*Connector) String

func (c *Connector) String() string

func (*Connector) UnsetWill

func (c *Connector) UnsetWill() *Connector

UnsetWill will cause any set will message to be disregarded.

Jump to

Keyboard shortcuts

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