messaging

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryWithBackoff

func RetryWithBackoff(attempts int, backoff time.Duration, callback func() error) (err error)

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
}

func (*Handler) OnConnect

func (h *Handler) OnConnect(c mq.Client)

onConnect gets executed when we've established a connection with the MQTT broker, regardless of if this was our first attempt or after a reconnect.

func (*Handler) OnConnectionLost

func (h *Handler) OnConnectionLost(c mq.Client, e error)

onConnectionLost gets triggered whenver we unexpectedly lose connection with the MQTT broker.

type Message

type Message interface {
	Topic() string
	Payload() []byte
}

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 Publisher

type Publisher interface {
	Publish(destination string, message []byte, qos int, persist bool)
}

Publisher publishes messages on a transport

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) Publish

func (m *TestingMQTTClient) Publish(topic string, qos byte, retained bool, payload interface{}) mq.Token

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

type TestingMQTTToken struct {
	mq.Token
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL