Documentation
¶
Index ¶
- Variables
- func CreateTopicWithIds(logger *otelzap.Logger, topicTemplate Topic, ids ...string) (string, error)
- func GetIdsFromTopic(logger *otelzap.Logger, actualTopic string, subTopic Topic) ([]string, error)
- type Client
- type ClientV5
- type Configuration
- type HandlerV5
- type MessageHandler
- type Topic
- type V5Impl
- func (c *V5Impl) Connect(ctx context.Context)
- func (c *V5Impl) Disconnect()
- func (c *V5Impl) Publish(ctx context.Context, topic Topic, message interface{}) error
- func (c *V5Impl) Subscribe(ctx context.Context, topic Topic, handler HandlerV5)
- func (c *V5Impl) SubscribeWithId(ctx context.Context, topic Topic, handler HandlerV5)
Constants ¶
This section is empty.
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") )
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()
Disconnect()
Publish(topic Topic, message interface{}) error
Subscribe(topic Topic, handler MessageHandler)
SubscribeToAny(topic Topic, handler MessageHandler)
GetId() string
}
Client is an interface wrapper for a simple MQTT client.
func NewMqttClient ¶
func NewMqttClient(clientSettings Configuration, obs observability.Observability) Client
NewMqttClient creates a wrapped mqtt Client with specific settings.
type ClientV5 ¶
type ClientV5 interface {
Connect(ctx context.Context)
Disconnect()
Publish(ctx context.Context, topic Topic, message interface{}) error
SubscribeWithId(ctx context.Context, topic Topic, handler HandlerV5)
Subscribe(ctx context.Context, topic Topic, handler HandlerV5)
}
ClientV5 is an interface wrapper for a simple MQTT client.
func NewMqttV5Client ¶
func NewMqttV5Client(clientSettings Configuration, obs observability.Observability) ClientV5
NewMqttV5Client creates a wrapped mqtt ClientV5 with specific settings.
type Configuration ¶
type Configuration struct {
Address string `validate:"required" json:"address" yaml:"address"`
Username string `fig:"username" yaml:"username"`
Password string `fig:"password" yaml:"password"`
ClientId string `fig:"clientId" validate:"required" yaml:"clientId"`
TLS configuration.TLS `fig:"tls" validate:"required" yaml:"tls"`
}
Configuration is the configuration for the MQTT client
type MessageHandler ¶
type V5Impl ¶
type V5Impl struct {
// contains filtered or unexported fields
}
V5Impl concrete implementation of the ClientV5, which is essentially a wrapper over the mqtt lib.
func (*V5Impl) Disconnect ¶
func (c *V5Impl) Disconnect()