Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ConnectionFailureError indicates a failure to connect to the MQTT broker. ConnectionFailureError = NewError("connection failure") // EmptyTopicError indicates that the topic for a subscription cannot be an empty string. EmptyTopicError = NewError("subscribe topic cannot be an empty string") // NillHandlerError indicates that the handler for a subscription cannot be nil. NillHandlerError = NewError("subscribe handler cannot be nil") // NillPayloadError indicates that the payload for a publish operation cannot be nil. NillPayloadError = NewError("publish payload cannot be nil") // InvalidQoSError indicates that the provided QoS value is invalid. InvalidQoSError = NewError("qos must be one of: byte(0), byte(1), or byte(2)") )
Functions ¶
func LogMessage ¶
LogMessage formats and returns a log message with a consistent prefix for MQTT operations.
func NewPublisher ¶
NewPublisher creates a new instance of mqttPublisher.
func ValidateQoS ¶
ValidateQoS checks if the provided QoS value is valid. It ensures the QoS is one of the defined levels: AtMostOnce, AtLeastOnce, or ExactlyOnce.
Types ¶
type Dispatcher ¶
type Dispatcher interface {
// Register adds a new subscription to the dispatcher with the specified topic, QoS, and handler.
// Returns an error if the topic is empty, the handler is nil, or the QoS is invalid.
Register(topic string, qos QoS, handler Handler) error
// ConsumeBlocking starts consuming messages for all registered subscriptions.
// Blocks until a signal is received on the provided channel, at which point it unsubscribes from all topics.
ConsumeBlocking()
}
Dispatcher is an interface for managing MQTT subscriptions and consuming messages.
func NewDispatcher ¶
func NewDispatcher(logger logging.Logger, client myQTT.Client) Dispatcher
NewDispatcher initializes a new mqttDispatcher with the provided logger and MQTT client.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a custom error type for the MQTT package.
type MQTTClient ¶
type MQTTClient interface {
// Connect establishes a connection to the MQTT broker.
Connect() error
// Client returns the underlying MQTT client instance.
Client() myQTT.Client
}
MQTTClient defines the interface for an MQTT client.
func NewMQTTClient ¶
func NewMQTTClient(cfgs *configs.Configs) MQTTClient
NewMQTTClient creates a new instance of mqttClient.
type QoS ¶
type QoS byte
QoS represents the Quality of Service levels for MQTT messages. It defines the reliability of message delivery between the client and broker. - AtMostOnce: Messages are delivered at most once (0). - AtLeastOnce: Messages are delivered at least once (1). - ExactlyOnce: Messages are delivered exactly once (2).
func QoSFromBytes ¶
QoSFromBytes converts a byte value to a QoS type. It maps the byte to one of the defined QoS levels.