Versions in this module Expand all Collapse all v1 v1.0.0 Apr 14, 2025 Changes in this version + var DroppedMessages = prometheus.NewCounterVec(prometheus.CounterOpts{ ... }, []string{ ... }) + var ErrClientConnected = errors.New("MQTT client is connected") + var ErrClientConnecting = errors.New("MQTT client is connecting") + var ErrClientNotConnected = errors.New("MQTT client is not connected") + var ErrInvalidConfig = errors.New("invalid MQTT client configuration") + var ErrMaxReconnectAttempts = errors.New("maximum reconnect attempts reached") + type ClientOption func(*MQTTClient) + func WithLogger(logger *zap.Logger) ClientOption + func WithMessageHandler(handler MessageHandler) ClientOption + type ConfigOption func(*MQTTConfig) + func WithBroker(broker string) ConfigOption + func WithCleanSession(cleanSession bool) ConfigOption + func WithClientID(clientID string) ConfigOption + func WithConnectTimeout(timeout time.Duration) ConfigOption + func WithCredentials(username, password string) ConfigOption + func WithFullChannelRetries(retries int) ConfigOption + func WithFullChannelStrategy(strategy FullChannelStrategy) ConfigOption + func WithHealthCheck(interval time.Duration, activeCheckEnabled bool, activeCheckTopic *string) ConfigOption + func WithKeepAlive(keepalive time.Duration) ConfigOption + func WithMessageChannelSize(size int) ConfigOption + func WithPort(port int) ConfigOption + func WithQoS(qos byte) ConfigOption + func WithReconnectOnDisconnect(initialDelay, maxDelay time.Duration, delayMultiplier float64, maxRetries int) ConfigOption + func WithTopic(topic string) ConfigOption + type ConnectionState int32 + const StateConnected + const StateConnecting + const StateDisconnected + type FullChannelStrategy int + const Block + const DropCurrent + const DropOldest + type HealthCheckConfig struct + type MQTTClient struct + func NewMQTTClient(cfg *MQTTConfig, opts ...ClientOption) (*MQTTClient, error) + func (c *MQTTClient) AddHandler(handler MessageHandler) + func (c *MQTTClient) Close() error + func (c *MQTTClient) Connect() error + func (c *MQTTClient) GetMessageChannel() <-chan mqtt.Message + func (c *MQTTClient) Subscribe(ctx context.Context) error + func (m *MQTTClient) State() ConnectionState + type MQTTConfig struct + func NewMQTTConfig(opts ...ConfigOption) (*MQTTConfig, error) + func (c *MQTTConfig) GetBroker() string + func (c *MQTTConfig) GetCleanSession() bool + func (c *MQTTConfig) GetClientID() string + func (c *MQTTConfig) GetConnectTimeout() time.Duration + func (c *MQTTConfig) GetFullChannelRetries() int + func (c *MQTTConfig) GetFullChannelStrategy() FullChannelStrategy + func (c *MQTTConfig) GetHealthCheckConfig() HealthCheckConfig + func (c *MQTTConfig) GetKeepAlive() time.Duration + func (c *MQTTConfig) GetMessageChannelSize() int + func (c *MQTTConfig) GetPort() int + func (c *MQTTConfig) GetQoS() byte + func (c *MQTTConfig) GetReconnectConfig() *ReconnectConfig + func (c *MQTTConfig) GetTopic() string + type MessageHandler func(mqtt.Message) error + type MessageQueue struct + func NewMessageQueue(bufferSize int, workers int) *MessageQueue + func (mq *MessageQueue) Enqueue(msg mqtt.Message) + func (mq *MessageQueue) StartProcessing(handler func(mqtt.Message)) + type ReconnectConfig struct