Documentation ¶
Index ¶
- Variables
- func NewTrie() *trie
- func NewTrieMQTT() *trie
- func WithAutoReconnect(a bool) func(*Client)
- func WithBrokers(brokers ...string) func(*Client)
- func WithClientID(id string) func(*Client)
- func WithConnectTimeout(t time.Duration) func(*Client)
- func WithKeepAlive(k time.Duration) func(*Client)
- func WithLogger(logger *zap.Logger) func(*Client)
- func WithMatcher(matcher string) func(*Client)
- func WithMaxReconnectInterval(t time.Duration) func(*Client)
- func WithPassword(password string) func(*Client)
- func WithPingTimeout(k time.Duration) func(*Client)
- func WithTLSConfig(t *tls.Config) func(*Client)
- func WithUsername(username string) func(*Client)
- type Client
- func (c *Client) AllowKey(secretKey, targetKey string) (bool, error)
- func (c *Client) BlockKey(secretKey, targetKey string) (bool, error)
- func (c *Client) Connect() error
- func (c *Client) CreateLink(key, channel, name string, optionalHandler MessageHandler, options ...Option) (*Link, error)
- func (c *Client) Disconnect(waitTime time.Duration)
- func (c *Client) GenerateKey(key, channel, permissions string, ttl int) (string, error)
- func (c *Client) ID() string
- func (c *Client) IsConnected() bool
- func (c *Client) OnConnect(handler ConnectHandler)
- func (c *Client) OnDisconnect(handler DisconnectHandler)
- func (c *Client) OnError(handler ErrorHandler)
- func (c *Client) OnMessage(handler MessageHandler)
- func (c *Client) OnPresence(handler PresenceHandler)
- func (c *Client) Presence(key, channel string, status, changes bool) error
- func (c *Client) Publish(key string, channel string, payload interface{}, options ...Option) error
- func (c *Client) PublishWithLink(name string, payload interface{}, options ...Option) error
- func (c *Client) PublishWithRetain(key string, channel string, payload interface{}, options ...Option) error
- func (c *Client) PublishWithTTL(key string, channel string, payload interface{}, ttl int) error
- func (c *Client) Subscribe(key string, channel string, optionalHandler MessageHandler, options ...Option) error
- func (c *Client) SubscribeWithGroup(key, channel, shareGroup string, optionalHandler MessageHandler, ...) error
- func (c *Client) SubscribeWithHistory(key string, channel string, last int, optionalHandler MessageHandler) error
- func (c *Client) Unsubscribe(key string, channel string) error
- type ConnectHandler
- type DisconnectHandler
- type Error
- type ErrorHandler
- type Link
- type Message
- type MessageHandler
- type Option
- type PresenceEvent
- type PresenceHandler
- type PresenceInfo
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( ErrTimeout = errors.New("emitter: operation has timed out") ErrUnmarshal = errors.New("emitter: unable to unmarshal the response") )
Various emitter errors
Functions ¶
func NewTrie ¶
func NewTrie() *trie
NewTrie creates a new subscriptions matcher using standard emitter strategy.
func NewTrieMQTT ¶
func NewTrieMQTT() *trie
NewTrieMQTT creates a new subscriptions matcher using standard MQTT strategy.
func WithAutoReconnect ¶
WithAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the ConnectionLostHandler is still called
func WithBrokers ¶
WithBrokers configures broker URIs to connect to. 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.
func WithClientID ¶
WithClientID 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 WithConnectTimeout ¶
WithConnectTimeout 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 WithKeepAlive ¶
WithKeepAlive 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 WithMatcher ¶
WithMatcher If "mqtt", then topic matching would follow MQTT specification.
func WithMaxReconnectInterval ¶
WithMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts when connection is lost
func WithPassword ¶
WithPassword 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 WithPingTimeout ¶
WithPingTimeout 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 WithTLSConfig ¶
WithTLSConfig 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 WithUsername ¶
WithUsername 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.
Types ¶
type Client ¶
Client represents an emitter client which holds the connection.
func Connect ¶
func Connect(host string, handler MessageHandler, options ...func(*Client)) (*Client, error)
Connect is a convenience function which sets a broker and connects to it.
func NewClient ¶
NewClient will create an MQTT v3.1.1 client with all of the options specified in the provided ClientOptions. The client must have the Connect method called on it before it may be used. This is to make sure resources (such as a net connection) are created before the application is actually ready.
func (*Client) CreateLink ¶
func (c *Client) CreateLink(key, channel, name string, optionalHandler MessageHandler, options ...Option) (*Link, error)
CreateLink sends a request to create a default link.
func (*Client) Disconnect ¶
Disconnect will end the connection with the server, but not before waiting the specified number of milliseconds to wait for existing work to be completed.
func (*Client) GenerateKey ¶
GenerateKey sends a key generation request to the broker
func (*Client) IsConnected ¶
IsConnected returns a bool signifying whether the client is connected or not.
func (*Client) OnConnect ¶
func (c *Client) OnConnect(handler ConnectHandler)
OnConnect sets the function to be called when the client is connected. Both at initial connection time and upon automatic reconnect.
func (*Client) OnDisconnect ¶
func (c *Client) OnDisconnect(handler DisconnectHandler)
OnDisconnect will set the function callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker.
func (*Client) OnError ¶
func (c *Client) OnError(handler ErrorHandler)
OnError will set the function callback to be executed if an emitter-specific error occurs.
func (*Client) OnMessage ¶
func (c *Client) OnMessage(handler MessageHandler)
OnMessage sets the MessageHandler that will be called when a message is received that does not match any known subscriptions.
func (*Client) OnPresence ¶
func (c *Client) OnPresence(handler PresenceHandler)
OnPresence sets the function that will be called when a presence event is received.
func (*Client) Publish ¶
Publish will publish a message with the specified QoS and content to the specified topic. Returns a token to track delivery of the message to the broker
func (*Client) PublishWithLink ¶
PublishWithLink publishes a message with a specified link name instead of a channel key.
func (*Client) PublishWithRetain ¶
func (c *Client) PublishWithRetain(key string, channel string, payload interface{}, options ...Option) error
PublishWithRetain publishes a message with a retain flag set to true
func (*Client) PublishWithTTL ¶
PublishWithTTL publishes a message with a specified Time-To-Live option
func (*Client) Subscribe ¶
func (c *Client) Subscribe(key string, channel string, optionalHandler MessageHandler, options ...Option) error
Subscribe starts a new subscription. Provide a MessageHandler to be executed when a message is published on the topic provided.
func (*Client) SubscribeWithGroup ¶
func (c *Client) SubscribeWithGroup(key, channel, shareGroup string, optionalHandler MessageHandler, options ...Option) error
SubscribeWithGroup creates a shared subscription to a share group.
func (*Client) SubscribeWithHistory ¶
func (c *Client) SubscribeWithHistory(key string, channel string, last int, optionalHandler MessageHandler) error
SubscribeWithHistory performs a subscribe with an option to retrieve the specified number of messages that were already published in the channel.
type ConnectHandler ¶
type ConnectHandler func(*Client)
ConnectHandler is a callback that is called when the client state changes from unconnected/disconnected to connected. Both at initial connection and on reconnection
type DisconnectHandler ¶
DisconnectHandler is a callback type which can be set to be executed upon an unintended disconnection from the MQTT broker. Disconnects caused by calling Disconnect or ForceDisconnect will not cause an OnConnectionLost callback to execute.
type Error ¶
type Error struct { Request uint16 `json:"req,omitempty"` Status int `json:"status"` Message string `json:"message"` }
Error represents an event code which provides a more details.
type ErrorHandler ¶
ErrorHandler is a callback type which can be set to be executed upon the arrival of an emitter error.
type Link ¶
type Link struct { Request uint16 `json:"req,omitempty"` Name string `json:"name,omitempty"` // The name of the shortcut, max 2 characters. Channel string `json:"channel,omitempty"` // The channel which was registered. }
Link represents a response for the link creation.
type Message ¶
Message defines the externals that a message implementation must support these are received messages that are passed to the callbacks, not internal messages
type MessageHandler ¶
MessageHandler is a callback type which can be set to be executed upon the arrival of messages published to topics to which the client is subscribed.
type Option ¶
type Option interface {
String() string
}
Option represents a key/value pair that can be supplied to the publish/subscribe or unsubscribe methods and provide ways to configure the operation.
func WithAtLeastOnce ¶
func WithAtLeastOnce() Option
WithAtLeastOnce instructs to publish at least once (MQTT QoS 1).
func WithAtMostOnce ¶
func WithAtMostOnce() Option
WithAtMostOnce instructs to publish at most once (MQTT QoS 0).
func WithLast ¶
WithLast constructs an option which can be used during subscribe requests to retrieve a message history.
func WithRetain ¶
func WithRetain() Option
WithRetain constructs an option which sets the message 'retain' flag to true.
func WithTTL ¶
WithTTL constructs an option which can be used during publish requests to set a Time-To-Live.
func WithoutEcho ¶
func WithoutEcho() Option
WithoutEcho constructs an option which disables self-receiving messages if subscribed to a channel.
type PresenceEvent ¶
type PresenceEvent struct { Who []PresenceInfo // contains filtered or unexported fields }
PresenceEvent represents a response from emitter broker which contains presence state or a join/leave notification.
func (*PresenceEvent) RequestID ¶
func (r *PresenceEvent) RequestID() uint16
RequestID returns the request ID for the response.
type PresenceHandler ¶
type PresenceHandler func(*Client, PresenceEvent)
PresenceHandler is a callback type which can be set to be executed upon the arrival of presence events.
type PresenceInfo ¶
PresenceInfo represents a response from emitter broker which contains presence information.