mqtt

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout           = 5  // seconds
	DefaultConnectionTimeout = 30 // seconds

	ErrMissingBroker   = utils.Error("at least one broker must be specified")
	ErrInvalidProtocol = utils.Error("invalid protocol")
	ErrInvalidTimeout  = utils.Error("invalid timeout")
	ErrInvalidQoSLevel = utils.Error("invalid QoS level")
	ErrPublishTimeout  = utils.Error("timeout when publishing")

	ErrNilConfig = utils.Error("Config is nil")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ClientOptions *paho.ClientOptions
	Client        paho.Client
	QoS           byte
	Timeout       time.Duration
	Retain        bool
}

func NewClient

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

func (*Client) AddRoute

func (c *Client) AddRoute(topic string, handler paho.MessageHandler)

func (*Client) BufferedChannelSubscribe added in v0.3.0

func (c *Client) BufferedChannelSubscribe(topic string, qos byte, ch chan paho.Message, bufferSize int) error

BufferedChannelSubscribe is an enhanced version of ChannelSubscribe with buffer size control to avoid blocking on channel sends

func (*Client) ChannelSubscribe

func (c *Client) ChannelSubscribe(topic string, qos byte, ch chan paho.Message) error

ChannelSubscribe subscribes to a topic and sends messages to the provided channel

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect() (bool, error)

func (*Client) CustomSettings

func (c *Client) CustomSettings() error

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, qos byte, handler paho.MessageHandler) error

func (*Client) SubscribeMultiple

func (c *Client) SubscribeMultiple(filters map[string]byte, handler paho.MessageHandler) error

func (*Client) Write

func (c *Client) Write(topic string, value []byte) error

func (*Client) WriteJson

func (c *Client) WriteJson(topic string, value interface{}) error

type Config

type Config struct {
	Brokers                        []string `json:"brokers"`
	Protocol                       string   `json:"protocol"`
	Username                       string   `json:"username"`
	secure.DefaultCredentialConfig          // connection credential
	Timeout                        int      `json:"timeout"`
	ConnectionTimeout              int      `json:"connectionTimeout"`
	QoS                            int      `json:"qos"`
	ClientID                       string   `json:"clientId"`
	Retain                         bool     `json:"retain"`
	KeepAlive                      int64    `json:"keepAlive"`
	AutoReconnect                  bool     `json:"autoReconnect"`
	PersistentSession              bool     `json:"persistentSession"`
	tlsProvider.ClientConfig
	MqttHandlers `json:"-"`
	// contains filtered or unexported fields
}

SecureConfig struct with secure password handling

func NewConfig

func NewConfig() *Config

NewConfig creates a new configuration with secure defaults

func (*Config) Validate

func (c *Config) Validate() error

type MqttHandlers

type MqttHandlers struct {
	DefaultPublishHandler  paho.MessageHandler
	OnConnect              paho.OnConnectHandler
	OnConnectionLost       paho.ConnectionLostHandler
	OnReconnecting         paho.ReconnectHandler
	OnConnectAttempt       paho.ConnectionAttemptHandler
	CustomOpenConnectionFn paho.OpenConnectionFunc
}

Jump to

Keyboard shortcuts

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