Documentation ¶
Index ¶
- func RetryWithBackoff(attempts int, backoff time.Duration, callback func() error) (err error)
- type Handler
- type Message
- type PublishSubscriber
- type Publisher
- type Subscriber
- type TestingMQTTClient
- func (m *TestingMQTTClient) AddRoute(topic string, callback mq.MessageHandler)
- func (m *TestingMQTTClient) Connect() mq.Token
- func (m *TestingMQTTClient) Disconnect(uint)
- func (m *TestingMQTTClient) IsConnected() bool
- func (m *TestingMQTTClient) IsConnectionOpen() bool
- func (m *TestingMQTTClient) OptionsReader() mq.ClientOptionsReader
- func (m *TestingMQTTClient) Publish(topic string, qos byte, retained bool, payload interface{}) mq.Token
- func (m *TestingMQTTClient) Subscribe(topic string, qos byte, callback mq.MessageHandler) mq.Token
- func (m *TestingMQTTClient) SubscribeMultiple(filters map[string]byte, callback mq.MessageHandler) mq.Token
- func (m *TestingMQTTClient) Unsubscribe(topics ...string) mq.Token
- type TestingMQTTToken
- type TestingMessenger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RetryWithBackoff ¶
RetryWithBackoff will retry the operation for the amount of attempts. The backoff time gets multiplied by the attempt to create an exponential backoff.
Returns an error if the operation still failed after the specified amount of attempts have been executed.
Types ¶
type Handler ¶
type Handler struct { Ann chan Message Leave chan Message AnnounceTopic string LeaveTopic string DiscoverTopic string DiscoverDelay time.Duration DiscoverStart chan bool }
type PublishSubscriber ¶
type PublishSubscriber interface { Publisher Subscriber }
PublishSubscriber can both publish and receives messages from a transport
func NewMQTTMessenger ¶
func NewMQTTMessenger(client mq.Client) PublishSubscriber
NewMQTTMessenger returns a PublishSubscriber.
It expects to be given something that looks like an MQTT Client and a channel on which it will publish any messages from topics to which we have subscribed.
It allows for publishing messages to a topic on an MQTT broker, to subscribe to messages published to topics and to unsubscribe from topic.
func NewTestingMessenger ¶
func NewTestingMessenger(client mq.Client) PublishSubscriber
type Subscriber ¶
type Subscriber interface { Subscribe(source string, qos int, callback func(Message)) Unsubscribe(sources ...string) }
Subscriber receives messages from a transport
type TestingMQTTClient ¶
type TestingMQTTClient struct {
ConnectionState bool
}
func (*TestingMQTTClient) AddRoute ¶
func (m *TestingMQTTClient) AddRoute(topic string, callback mq.MessageHandler)
func (*TestingMQTTClient) Connect ¶
func (m *TestingMQTTClient) Connect() mq.Token
func (*TestingMQTTClient) Disconnect ¶
func (m *TestingMQTTClient) Disconnect(uint)
func (*TestingMQTTClient) IsConnected ¶
func (m *TestingMQTTClient) IsConnected() bool
TestingMQTTClient can be used in place of an mq.Client. It is meant to be used in tests
func (*TestingMQTTClient) IsConnectionOpen ¶ added in v0.3.0
func (m *TestingMQTTClient) IsConnectionOpen() bool
func (*TestingMQTTClient) OptionsReader ¶ added in v0.3.0
func (m *TestingMQTTClient) OptionsReader() mq.ClientOptionsReader
func (*TestingMQTTClient) Subscribe ¶
func (m *TestingMQTTClient) Subscribe(topic string, qos byte, callback mq.MessageHandler) mq.Token
func (*TestingMQTTClient) SubscribeMultiple ¶
func (m *TestingMQTTClient) SubscribeMultiple(filters map[string]byte, callback mq.MessageHandler) mq.Token
func (*TestingMQTTClient) Unsubscribe ¶
func (m *TestingMQTTClient) Unsubscribe(topics ...string) mq.Token
type TestingMQTTToken ¶
TestingMQTTToken can be used in place of an mq.Token. It is meant to be used in tests
func (*TestingMQTTToken) Error ¶
func (t *TestingMQTTToken) Error() error
func (*TestingMQTTToken) Wait ¶
func (t *TestingMQTTToken) Wait() bool
func (*TestingMQTTToken) WaitTimeout ¶
func (t *TestingMQTTToken) WaitTimeout(time.Duration) bool
type TestingMessenger ¶
type TestingMessenger struct { Action string Topic []string Message []byte Qos int Persist bool Callback func(Message) // contains filtered or unexported fields }
TestingMessenger is a no-op messenger useful for when running tests
func (*TestingMessenger) Publish ¶
func (tm *TestingMessenger) Publish(topic string, message []byte, qos int, persist bool)
func (*TestingMessenger) Subscribe ¶
func (tm *TestingMessenger) Subscribe(topic string, qos int, callback func(Message))
func (*TestingMessenger) Unsubscribe ¶
func (tm *TestingMessenger) Unsubscribe(topics ...string)