Documentation
¶
Index ¶
Constants ¶
const ( MqttVersion5 = "v5" MqttVersion3 = "v3" )
Variables ¶
var ( ErrNotValidSubscriptionTopic = fmt.Errorf("not a valid subscription topic") ErrNotSameTopic = fmt.Errorf("not the same topic") ErrNotSubscribedTopic = fmt.Errorf("not the subscribed topic") ErrInvalidArgs = fmt.Errorf("invalid number of arguments") ErrInvalidIds = fmt.Errorf("ids cannot be an empty string") )
var ErrInvalidVersion = errors.New("invalid MQTT version")
Functions ¶
func CreateTopicWithIds ¶
CreateTopicWithIds replaces all the + sign in a topic used for subscription with ids. Works only if the number of pluses is matches the number of ids.
func GetIdsFromTopic ¶
GetIdsFromTopic parses the topic received from the MQTT client and returns the ids based on the original subscription topic. For example: actual topic = some/exampleId1/subscription/exampleId2/topic subscription topic = some/+/subscription/+/topic should return ["exampleId1", "exampleId2"] If the topic are not the same length or don't contain the same words, it will return an error
Types ¶
type Client ¶
type Client interface {
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
Publish(ctx context.Context, topic Topic, message interface{}) error
// PublishRPC(ctx context.Context, topic Topic, message interface{}) error
SubscribeWithId(ctx context.Context, topic Topic, handler Handler)
Subscribe(ctx context.Context, topic Topic, handler Handler) error
GetId() string
checks.Check
}
Client is an interface wrapper for a simple MQTT client.
func NewClientFromConfig ¶ added in v0.2.0
func NewClientFromConfig(obs observability.Observability, cfg Configuration) (Client, error)
NewClientFromConfig Creates a new MQTT client from the configuration based on the supported version.
func NewV3Client ¶ added in v0.2.0
func NewV3Client(clientSettings Configuration, obs observability.Observability) (Client, error)
NewV3Client creates a wrapped mqtt Client with specific settings.
func NewV5Client ¶ added in v0.2.0
func NewV5Client(clientSettings Configuration, obs observability.Observability) (Client, error)
NewV5Client creates a wrapped mqtt ClientV5 with specific settings.
type Configuration ¶
type Configuration struct {
Version string `yaml:"version"`
Address string `validate:"required,url" json:"address" yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
ClientId string `validate:"required" yaml:"clientId"`
TLS tls.TLS `validate:"required" yaml:"tls"`
}
Configuration is the configuration for the MQTT client