mqtt

package
v1.40.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 14 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMQTTv5Client

func NewMQTTv5Client(cfg *MqttConfig) (*mqttv5Client, error)

func NewMQTTv311Client

func NewMQTTv311Client(cfg *MqttConfig) (*mqttv311Client, error)

Types

type Client

type Client interface {
	Connect() (bool, error)
	Publish(topic string, data []byte) error
	SubscribeMultiple(filters map[string]byte, callback paho.MessageHandler) error
	AddRoute(topic string, callback paho.MessageHandler)
	Close() error
}

Client is a protocol neutral MQTT client for connecting, disconnecting, and publishing data to a topic. The protocol specific clients must implement this interface

func NewClient

func NewClient(cfg *MqttConfig) (Client, error)

type MqttConfig

type MqttConfig struct {
	Servers             []string           `toml:"servers"`
	Protocol            string             `toml:"protocol"`
	Username            config.Secret      `toml:"username"`
	Password            config.Secret      `toml:"password"`
	Timeout             config.Duration    `toml:"timeout"`
	ConnectionTimeout   config.Duration    `toml:"connection_timeout"`
	QoS                 int                `toml:"qos"`
	ClientID            string             `toml:"client_id"`
	Retain              bool               `toml:"retain"`
	KeepAlive           int64              `toml:"keep_alive"`
	PersistentSession   bool               `toml:"persistent_session"`
	PublishPropertiesV5 *PublishProperties `toml:"v5"`
	ClientTrace         bool               `toml:"client_trace" deprecated:"1.37.0;1.45.0;use 'log_level' 'trace' instead"`

	tls.ClientConfig

	AutoReconnect    bool        `toml:"-"`
	OnConnectionLost func(error) `toml:"-"`
}

type PublishProperties

type PublishProperties struct {
	ContentType    string            `toml:"content_type"`
	ResponseTopic  string            `toml:"response_topic"`
	MessageExpiry  config.Duration   `toml:"message_expiry"`
	TopicAlias     *uint16           `toml:"topic_alias"`
	UserProperties map[string]string `toml:"user_properties"`
}

PublishProperties for mqtt v5-specific properties. See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109

Jump to

Keyboard shortcuts

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