Documentation ¶
Index ¶
- type Client
- func (c *Client) Publish(topic string, qos uint8, msg io.Reader) error
- func (c *Client) Start(uri string, cleanSession bool) error
- func (c *Client) Stop() error
- func (c *Client) Subscribe(subscriber Subscriber, subscriptions ...Subscription)
- func (c *Client) SubscribeFunc(handler SubscriberFunc, subscriptions ...Subscription)
- type ClientOptions
- type MessageInfo
- type SessionManager
- type SessionMessage
- type SessionMessageType
- type Subscriber
- type SubscriberFunc
- type Subscription
- type Will
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(fallbackClientId string, opts *ClientOptions) *Client
func (*Client) Subscribe ¶
func (c *Client) Subscribe(subscriber Subscriber, subscriptions ...Subscription)
func (*Client) SubscribeFunc ¶
func (c *Client) SubscribeFunc(handler SubscriberFunc, subscriptions ...Subscription)
type ClientOptions ¶
type ClientOptions struct { Will *Will Session SessionManager }
type MessageInfo ¶
type SessionManager ¶
type SessionManager interface { // Gets the client id from the previous session, if there is no client id from the previous // session, then GetClientId must return empty string and nil error. The operation must be // atomic and idempotent. GetClientId() (string, error) // Sets the client id, overriding the previous client id saved. The operation must be atomic. SetClientId(string) error // Cleans the previous session, cleaning the underlying packet id table and the queue of // messages from the session. The operation must be atomic and idempotent. // // IMPORTANT: // // Implementators must have a transaction mechanism in which if some of the deletions fails, // the session should recover to its previous state as if this method had not been called. CleanSession() error // Returns a packet id that has not been used by any other packet. // // It's required not to mark it as used in the packet id table until SaveMessage is called. // The operation must be atomic. NewPacketId() (uint16, error) // Gets the following message in the previous session message queue. // // If after calling NextMessage, DiscardMessageById with id set to the message id is not // called, then calls to NextMessage should return the same SessionMessage until // DiscardMessageById is called. The operation must be atomic. // // Implementators should return nil message and nil error if there is no more messages in the // queue. NextMessage() (*SessionMessage, error) // Gets message by its id in the message table. The operation must be atomic. // // Implementators should return nil message and nil error if there is no message with such id. GetMessageById(uint16) (*SessionMessage, error) DiscardMessageById(uint16) error // Saves the message to the session manager. The operation must be atomic. // // IMPORTANT: // // Implementators must mark the packet id from this message as used in the packet id table if // it haven't been marked yet. SaveMessage(message SessionMessage) error }
Session manager that saves the state of the MQTT session, must be implemented if you want to subscribe or publish to topics with QoS > 0.
Can be implemented with SQL or NoSQL databases like MySQL or MongoDB.
It's discouraged to implement it with volatile environments such as temporal files or Go data structures.
type SessionMessage ¶
type SessionMessage struct { // Required in all of the instances of SessionMessage PacketId uint16 Type SessionMessageType // Required only if Type is SessionMessage_PUBLISH Qos uint8 // Payload should be nil if ToSend is false because this field will be ignored Payload []byte // Retain will be ignored if ToSend is false Retain bool // ToSend distinguishes between a packet to be send or a packet received // // true: A packet that will be send with DUP flag true if Type is PUBLISH // // false: A packet that was received as it is. A corresponding packet will be sent as response ToSend bool }
Represent a message to be saved to the SessionManager.
SessionMessage's returned by SessionManager are assumed to be duplicates when are sended to server.
type SessionMessageType ¶
type SessionMessageType int
const ( SessionMessage_PUBLISH SessionMessageType = 3 SessionMessage_PUBACK SessionMessageType = 4 SessionMessage_PUBREC SessionMessageType = 5 SessionMessage_PUBREL SessionMessageType = 6 SessionMessage_PUBCOMP SessionMessageType = 7 )
type Subscriber ¶
type Subscriber interface {
ReceiveMessage(message MessageInfo)
}
type SubscriberFunc ¶
type SubscriberFunc func(MessageInfo)
func (SubscriberFunc) ReceiveMessage ¶
func (f SubscriberFunc) ReceiveMessage(message MessageInfo)
type Subscription ¶
Click to show internal directories.
Click to hide internal directories.