mqtt

package
v0.0.0-...-2eeffc0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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 ContextKey

type ContextKey string

ContextKey is the type for context

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

func (c *MqttClient) Publish(ctx context.Context, topic string, qos byte, data []byte) error

Publish will publish a message with the specified QoS and content to the specified topic.

func (*MqttClient) PublishToSelf

func (c *MqttClient) PublishToSelf(ctx context.Context, prefix string, qos byte, data []byte) error

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.

Jump to

Keyboard shortcuts

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