Documentation
¶
Index ¶
- Constants
- type Connector
- func (c *Connector) AddBroker(server string) *Connector
- func (c *Connector) Close() error
- func (c *Connector) Connect() error
- func (c *Connector) Dial() error
- func (c *Connector) Disconnect()
- func (c *Connector) ID() string
- func (c *Connector) Listen(opts *connectors.SubscribeOptions, ch chan []byte) error
- func (c *Connector) Name() string
- func (c *Connector) On(opts *connectors.SubscribeOptions, f func([]byte)) error
- func (c *Connector) Put(opts *connectors.PublishOptions, msg []byte) error
- func (c *Connector) SetAutoReconnect(a bool) *Connector
- func (c *Connector) SetBinaryWill(topic string, payload []byte, qos byte, retained bool) *Connector
- func (c *Connector) SetCleanSession(clean bool) *Connector
- func (c *Connector) SetClientID(id string) *Connector
- func (c *Connector) SetConnectTimeout(t time.Duration) *Connector
- func (c *Connector) SetConnectionLostHandler(onLost MQTT.ConnectionLostHandler) *Connector
- func (c *Connector) SetDefaultPublishHandler(defaultHandler MQTT.MessageHandler) *Connector
- func (c *Connector) SetDefaultPublishOptions(opts *connectors.PublishOptions) *Connector
- func (c *Connector) SetDefaultSubscribeOptions(opts *connectors.SubscribeOptions) *Connector
- func (c *Connector) SetHTTPHeaders(h http.Header) *Connector
- func (c *Connector) SetKeepAlive(k time.Duration) *Connector
- func (c *Connector) SetMaxReconnectInterval(t time.Duration) *Connector
- func (c *Connector) SetMessageChannelDepth(s uint) *Connector
- func (c *Connector) SetOnConnectHandler(onConn MQTT.OnConnectHandler) *Connector
- func (c *Connector) SetOrderMatters(order bool) *Connector
- func (c *Connector) SetPassword(p string) *Connector
- func (c *Connector) SetPingTimeout(k time.Duration) *Connector
- func (c *Connector) SetProtocolVersion(pv uint) *Connector
- func (c *Connector) SetResumeSubs(resume bool) *Connector
- func (c *Connector) SetStore(s MQTT.Store) *Connector
- func (c *Connector) SetTLSConfig(t *tls.Config) *Connector
- func (c *Connector) SetUsername(u string) *Connector
- func (c *Connector) SetWill(topic string, payload string, qos byte, retained bool) *Connector
- func (c *Connector) SetWriteTimeout(t time.Duration) *Connector
- func (c *Connector) Stream(opts *connectors.PublishOptions, ch chan []byte) error
- func (c *Connector) String() string
- func (c *Connector) UnsetWill() *Connector
Constants ¶
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 ¶
func (*Connector) AddBroker ¶
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) Disconnect ¶
func (c *Connector) Disconnect()
Disconnect returns true if connection to mqtt is closed
func (*Connector) Listen ¶
func (c *Connector) Listen(opts *connectors.SubscribeOptions, ch chan []byte) error
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetHTTPHeaders sets the additional HTTP headers that will be sent in the WebSocket opening handshake.
func (*Connector) SetKeepAlive ¶
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 ¶
SetMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts when connection is lost
func (*Connector) SetMessageChannelDepth ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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