Documentation ¶
Overview ¶
Package mqtt is for testing MQTT clients and logic
Index ¶
- Constants
- type Connect
- type Connection
- type MockClient
- func (cli *MockClient) AddRoute(topic string, callback MQTT.MessageHandler)
- func (cli *MockClient) Connect() MQTT.Token
- func (cli *MockClient) Disconnect(quiesce uint)
- func (cli *MockClient) IsConnected() bool
- func (cli *MockClient) IsConnectionOpen() bool
- func (cli *MockClient) OptionsReader() MQTT.ClientOptionsReader
- func (cli *MockClient) Publish(topic string, qos byte, retained bool, payload interface{}) MQTT.Token
- func (cli *MockClient) Subscribe(topic string, qos byte, callback MQTT.MessageHandler) MQTT.Token
- func (cli *MockClient) SubscribeMultiple(filters map[string]byte, callback MQTT.MessageHandler) MQTT.Token
- func (cli *MockClient) Unsubscribe(topics ...string) MQTT.Token
- type MockConnect
- type MockMessage
- type MockToken
Constants ¶
const ( QOSAtMostOnce = byte(0) QOSAtLeastOnce = byte(1) )
Constants for connecting to the MQTT broker
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connect ¶
type Connect interface { Publish(topic, payload string) error Subscribe(topic string, callback MQTT.MessageHandler) error Close() }
Connect is the interface for an MQTT connection
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection for MQTT protocol
func GetConnection ¶
func GetConnection(url, port string, connect *config.MQTTConnect, onConnect func(c MQTT.Client)) (*Connection, error)
GetConnection fetches or creates an MQTT connection
func (*Connection) Close ¶
func (c *Connection) Close()
Close closes the connection to the MQTT broker
func (*Connection) Publish ¶
func (c *Connection) Publish(topic, payload string) error
Publish sends data to the MQTT broker
func (*Connection) Subscribe ¶
func (c *Connection) Subscribe(topic string, callback MQTT.MessageHandler) error
Subscribe starts a new subscription, providing a message handler for the topic
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
MockClient mocks the MQTT client
func (*MockClient) AddRoute ¶
func (cli *MockClient) AddRoute(topic string, callback MQTT.MessageHandler)
AddRoute mocks routing
func (*MockClient) Connect ¶
func (cli *MockClient) Connect() MQTT.Token
Connect mocks connecting to broker
func (*MockClient) Disconnect ¶
func (cli *MockClient) Disconnect(quiesce uint)
Disconnect mocks client close
func (*MockClient) IsConnected ¶
func (cli *MockClient) IsConnected() bool
IsConnected mocks the connect status
func (*MockClient) IsConnectionOpen ¶
func (cli *MockClient) IsConnectionOpen() bool
IsConnectionOpen mocks the connect status
func (*MockClient) OptionsReader ¶
func (cli *MockClient) OptionsReader() MQTT.ClientOptionsReader
OptionsReader mocks the options reader (badly)
func (*MockClient) Publish ¶
func (cli *MockClient) Publish(topic string, qos byte, retained bool, payload interface{}) MQTT.Token
Publish mocks a publish message
func (*MockClient) Subscribe ¶
func (cli *MockClient) Subscribe(topic string, qos byte, callback MQTT.MessageHandler) MQTT.Token
Subscribe mocks a subscribe message
func (*MockClient) SubscribeMultiple ¶
func (cli *MockClient) SubscribeMultiple(filters map[string]byte, callback MQTT.MessageHandler) MQTT.Token
SubscribeMultiple mocks subscribe messages
func (*MockClient) Unsubscribe ¶
func (cli *MockClient) Unsubscribe(topics ...string) MQTT.Token
Unsubscribe mocks a unsubscribe message
type MockConnect ¶
type MockConnect struct{}
MockConnect is a mock MQTT connection
func (*MockConnect) Publish ¶
func (c *MockConnect) Publish(topic, payload string) error
Publish mocks a MQTT publish method
func (*MockConnect) Subscribe ¶
func (c *MockConnect) Subscribe(topic string, callback MQTT.MessageHandler) error
Subscribe mocks a MQTT subscribe method
type MockMessage ¶
MockMessage implements an MQTT message
func (*MockMessage) Duplicate ¶
func (m *MockMessage) Duplicate() bool
Duplicate mocks a duplicate message check
func (*MockMessage) MessageID ¶
func (m *MockMessage) MessageID() uint16
MessageID mocks the message ID
func (*MockMessage) Payload ¶
func (m *MockMessage) Payload() []byte
Payload mocks the payload retrieval
func (*MockMessage) Retained ¶
func (m *MockMessage) Retained() bool
Retained mocks the retained flag