Documentation
¶
Index ¶
- type ClientOptions
- type ContextKey
- type MqttClient
- func (c *MqttClient) Connect(ctx context.Context) error
- func (c *MqttClient) Disconnect(ctx context.Context) error
- func (c *MqttClient) Publish(ctx context.Context, topic string, qos byte, data []byte) error
- func (c *MqttClient) PublishToSelf(ctx context.Context, prefix string, qos byte, data []byte) error
- func (c *MqttClient) Subscribe(ctx context.Context, topic string, qos byte, callback paho.MessageHandler) error
- func (c *MqttClient) SubscribeToSelf(ctx context.Context, prefix string, qos byte, callback paho.MessageHandler) error
- func (c *MqttClient) Unsubscribe(ctx context.Context, topics ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientOptions ¶
type ClientOptions struct {
*paho.ClientOptions
}
func NewClientOptions ¶
func NewClientOptions() *ClientOptions
type MqttClient ¶
type MqttClient struct {
// contains filtered or unexported fields
}
func NewMqttClient ¶
func NewMqttClient(ctx context.Context, opts *ClientOptions) (MqttClient, error)
func (*MqttClient) Connect ¶
func (c *MqttClient) Connect(ctx context.Context) error
Connect will create a connection to the message broker, by default it will attempt to connect at v3.1.1 and auto retry at v3.1 if that fails
func (*MqttClient) Disconnect ¶
func (c *MqttClient) Disconnect(ctx context.Context) error
Disconnect will end the connection with the server
func (*MqttClient) Publish ¶
Publish will publish a message with the specified QoS and content to the specified topic.
func (*MqttClient) PublishToSelf ¶
PublishToSelf starts a new publish. Topic is the concat of prefix and clientID. Provide a prefix, qos, and data
func (*MqttClient) Subscribe ¶
func (c *MqttClient) Subscribe( ctx context.Context, topic string, qos byte, callback paho.MessageHandler, ) error
Subscribe starts a new subscription. Provide a MessageHandler to be executed when a message is published on the topic provided. One different from the original paho is that when callback is nil the message will not be forwarded to the default handler.
func (*MqttClient) SubscribeToSelf ¶
func (c *MqttClient) SubscribeToSelf( ctx context.Context, prefix string, qos byte, callback paho.MessageHandler, ) error
SubscribeToSelf starts a new subscription. Topic is the concat of prefix and clientID. Provide a MessageHandler to be executed when a message is published on the topic provided. One different from the original paho is that when callback is nil the message will not be forwarded to the default handler.
func (*MqttClient) Unsubscribe ¶
func (c *MqttClient) Unsubscribe(ctx context.Context, topics ...string) error
Unsubscribe will end the subscription from each of the topics provided. Messages published to those topics from other clients will no longer be received.