Documentation
¶
Index ¶
- Variables
- type ClientOption
- type ConfigOption
- 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
- type FullChannelStrategy
- type HealthCheckConfig
- type MQTTClient
- type MQTTConfig
- 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
- type MessageQueue
- type ReconnectConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidConfig = errors.New("invalid MQTT client configuration") ErrClientNotConnected = errors.New("MQTT client is not connected") ErrClientConnected = errors.New("MQTT client is connected") ErrClientConnecting = errors.New("MQTT client is connecting") ErrMaxReconnectAttempts = errors.New("maximum reconnect attempts reached") )
var ( DroppedMessages = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "mqtt_dropped_messages_total", Help: "Total dropped messages by reason", }, []string{"reason"}, ) )
Functions ¶
This section is empty.
Types ¶
type ClientOption ¶
type ClientOption func(*MQTTClient)
ClientOption customizes the MQTT client behavior
func WithLogger ¶
func WithLogger(logger *zap.Logger) ClientOption
WithLogger sets the logger for the MQTT client
func WithMessageHandler ¶
func WithMessageHandler(handler MessageHandler) ClientOption
type ConfigOption ¶
type ConfigOption func(*MQTTConfig)
ConfigOption configures the MQTT client
func WithCleanSession ¶
func WithCleanSession(cleanSession bool) ConfigOption
WithCleanSession sets the clean session flag
func WithConnectTimeout ¶
func WithConnectTimeout(timeout time.Duration) ConfigOption
WithConnectTimeout sets the connection timeout
func WithCredentials ¶
func WithCredentials(username, password string) ConfigOption
WithCredentials sets the username and password for authentication
func WithFullChannelRetries ¶
func WithFullChannelRetries(retries int) ConfigOption
WithFullChannelRetries sets the number of retries for full channels
func WithFullChannelStrategy ¶
func WithFullChannelStrategy(strategy FullChannelStrategy) ConfigOption
WithFullChannelStrategy sets the strategy for handling full message channels
func WithHealthCheck ¶
func WithHealthCheck(interval time.Duration, activeCheckEnabled bool, activeCheckTopic *string) ConfigOption
WithHealthCheck sets the health check configuration
func WithKeepAlive ¶
func WithKeepAlive(keepalive time.Duration) ConfigOption
WithKeepAlive sets the keepalive interval
func WithMessageChannelSize ¶
func WithMessageChannelSize(size int) ConfigOption
WithMessageChannelSize sets the size of the message channel
func WithReconnectOnDisconnect ¶
func WithReconnectOnDisconnect(initialDelay, maxDelay time.Duration, delayMultiplier float64, maxRetries int) ConfigOption
WithReconnectOnDisconnect sets the reconnect configuration
type ConnectionState ¶
type ConnectionState int32
Constants and Types
const ( StateDisconnected ConnectionState = iota StateConnecting StateConnected )
type FullChannelStrategy ¶
type FullChannelStrategy int
FullChannelStrategy defines the strategy for handling full message channels
const ( DropOldest FullChannelStrategy = iota // Default DropCurrent Block )
type HealthCheckConfig ¶
type HealthCheckConfig struct {
// contains filtered or unexported fields
}
type MQTTClient ¶
type MQTTClient struct {
// contains filtered or unexported fields
}
MQTTClient represents a managed MQTT client connection
func NewMQTTClient ¶
func NewMQTTClient(cfg *MQTTConfig, opts ...ClientOption) (*MQTTClient, error)
NewMQTTClient creates a new managed MQTT client
func (*MQTTClient) AddHandler ¶
func (c *MQTTClient) AddHandler(handler MessageHandler)
AddHandler adds a message handler to the client
func (*MQTTClient) Close ¶
func (c *MQTTClient) Close() error
Close closes the MQTT client connection
func (*MQTTClient) Connect ¶
func (c *MQTTClient) Connect() error
Connect establishes a connection to the MQTT broker
func (*MQTTClient) GetMessageChannel ¶
func (c *MQTTClient) GetMessageChannel() <-chan mqtt.Message
--------------------------------Message Handling---------------------------- GetMessageChannel returns the message channel for receiving messages
func (*MQTTClient) State ¶
func (m *MQTTClient) State() ConnectionState
type MQTTConfig ¶
type MQTTConfig struct {
// contains filtered or unexported fields
}
MQTTConfig holds client configuration
func NewMQTTConfig ¶
func NewMQTTConfig(opts ...ConfigOption) (*MQTTConfig, error)
NewMQTTConfig creates a new MQTTConfig with default values
func (*MQTTConfig) GetBroker ¶
func (c *MQTTConfig) GetBroker() string
Getter functions GetBroker returns the broker address
func (*MQTTConfig) GetCleanSession ¶
func (c *MQTTConfig) GetCleanSession() bool
GetCleanSession returns the clean session flag
func (*MQTTConfig) GetClientID ¶
func (c *MQTTConfig) GetClientID() string
GetClientID returns the client ID
func (*MQTTConfig) GetConnectTimeout ¶
func (c *MQTTConfig) GetConnectTimeout() time.Duration
GetConnectTimeout returns the connection timeout
func (*MQTTConfig) GetFullChannelRetries ¶
func (c *MQTTConfig) GetFullChannelRetries() int
GetFullChannelRetries returns the number of retries for full channels
func (*MQTTConfig) GetFullChannelStrategy ¶
func (c *MQTTConfig) GetFullChannelStrategy() FullChannelStrategy
GetFullChannelStrategy returns the strategy for handling full message channels
func (*MQTTConfig) GetHealthCheckConfig ¶
func (c *MQTTConfig) GetHealthCheckConfig() HealthCheckConfig
GetHealthCheckConfig returns the health check configuration
func (*MQTTConfig) GetKeepAlive ¶
func (c *MQTTConfig) GetKeepAlive() time.Duration
GetKeepAlive returns the keepalive interval
func (*MQTTConfig) GetMessageChannelSize ¶
func (c *MQTTConfig) GetMessageChannelSize() int
GetMessageChannelSize returns the size of the message channel
func (*MQTTConfig) GetQoS ¶
func (c *MQTTConfig) GetQoS() byte
GetQoS returns the Quality of Service level
func (*MQTTConfig) GetReconnectConfig ¶
func (c *MQTTConfig) GetReconnectConfig() *ReconnectConfig
GetReconnectConfig returns the reconnect configuration
func (*MQTTConfig) GetTopic ¶
func (c *MQTTConfig) GetTopic() string
GetTopic returns the topic to subscribe to
type MessageHandler ¶
MessageHandler processes incoming MQTT messages
type MessageQueue ¶
type MessageQueue struct {
// contains filtered or unexported fields
}
MessageQueue handles queuing and processing messages
func NewMessageQueue ¶
func NewMessageQueue(bufferSize int, workers int) *MessageQueue
NewMessageQueue creates a new message queue with a specified buffer size
func (*MessageQueue) Enqueue ¶
func (mq *MessageQueue) Enqueue(msg mqtt.Message)
Enqueue adds a message to the queue
func (*MessageQueue) StartProcessing ¶
func (mq *MessageQueue) StartProcessing(handler func(mqtt.Message))
StartProcessing starts worker goroutines to process messages from the queue
type ReconnectConfig ¶
type ReconnectConfig struct {
// contains filtered or unexported fields
}
ReconnectConfig holds configuration for reconnecting