mqtt

package
v0.0.0-...-cf35b07 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Different Client operations.
	PublishOperation   = "Publish"
	SubscribeOperation = "Subscribe"
	ConnectOperation   = "Connect"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client facilitates communication to an MQTT server and provides functionality needed to send and receive MQTT messages.

func NewMQTTClient

func NewMQTTClient(config types.MessageBusConfig) (*Client, error)

NewMQTTClient constructs a new MQTT client based on the options provided.

func NewMQTTClientWithCreator

func NewMQTTClientWithCreator(
	config types.MessageBusConfig,
	marshaller MessageMarshaller,
	unmarshaller MessageUnmarshaller,
	creator ClientCreator) (*Client, error)

NewMQTTClientWithCreator constructs a new MQTT client based on the options and ClientCreator provided.

func (*Client) Connect

func (mc *Client) Connect() error

Connect establishes a connection to a MQTT server. This must be called before any other functionality provided by the Client.

func (*Client) Disconnect

func (mc *Client) Disconnect() error

Disconnect closes the connection to the connected MQTT server.

func (*Client) Publish

func (mc *Client) Publish(message types.MessageEnvelope, topic string) error

Publish sends a message to the connected MQTT server.

func (*Client) Subscribe

func (mc *Client) Subscribe(topics []types.TopicChannel, messageErrors chan error) error

Subscribe creates a subscription for the specified topics.

type ClientCreator

type ClientCreator func(config types.MessageBusConfig, handler pahoMqtt.OnConnectHandler) (pahoMqtt.Client, error)

ClientCreator defines the function signature for creating an MQTT client.

func ClientCreatorWithCertLoader

func ClientCreatorWithCertLoader(certCreator pkg.X509KeyPairCreator, certLoader pkg.X509KeyLoader) ClientCreator

ClientCreatorWithCertLoader creates a ClientCreator which leverages the specified cert creator and loader when creating an MQTT client.

func DefaultClientCreator

func DefaultClientCreator() ClientCreator

DefaultClientCreator returns a default function for creating MQTT clients.

type ConnectionOptions

type ConnectionOptions struct {
	BrokerURL string
}

ConnectionOptions contains the connection configurations for the MQTT client.

NOTE: The connection properties resides in its own struct in order to avoid the property being loaded in via

reflection during the load process.

type MQTTClientConfig

type MQTTClientConfig struct {
	BrokerURL string
	MQTTClientOptions
}

MQTTClientConfig contains all the configurations for the MQTT client.

func CreateMQTTClientConfiguration

func CreateMQTTClientConfiguration(messageBusConfig types.MessageBusConfig) (MQTTClientConfig, error)

CreateMQTTClientConfiguration constructs a MQTTClientConfig based on the provided MessageBusConfig.

type MQTTClientOptions

type MQTTClientOptions struct {
	// Client Identifiers
	Username string
	Password string
	ClientId string
	// Connection information
	Qos            int
	KeepAlive      int // Seconds
	Retained       bool
	AutoReconnect  bool
	ConnectTimeout int // Seconds
	pkg.TlsConfigurationOptions
}

MQTTClientOptions contains the client options which are loaded via reflection

func CreateMQTTClientOptionsWithDefaults

func CreateMQTTClientOptionsWithDefaults() MQTTClientOptions

CreateMQTTClientOptionsWithDefaults constructs MQTTClientOptions instance with defaults.

type MessageMarshaller

type MessageMarshaller func(v interface{}) ([]byte, error)

MessageMarshaller defines the function signature for marshaling structs into []byte.

type MessageUnmarshaller

type MessageUnmarshaller func(data []byte, v interface{}) error

MessageUnmarshaller defines the function signature for unmarshaling []byte into structs.

type OperationErr

type OperationErr struct {
	// contains filtered or unexported fields
}

OperationErr defines an error representing operations which have failed.

func NewOperationErr

func NewOperationErr(operation string, message string) OperationErr

NewOperationErr creates a new OperationErr

func (OperationErr) Error

func (oe OperationErr) Error() string

type TimeoutErr

type TimeoutErr struct {
	// contains filtered or unexported fields
}

TimeoutErr defines an error representing operations which have not completed and surpassed the allowed wait time.

func NewTimeoutError

func NewTimeoutError(operation string, message string) TimeoutErr

NewTimeoutError creates a new TimeoutErr.

func (TimeoutErr) Error

func (te TimeoutErr) Error() string

Jump to

Keyboard shortcuts

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