# README
mqtt-go
Yet another Go MQTT 3.1.1 client library
- Go-ish interface
Fully context controlled and mockable interface.
- Extensible
Easy to implement a wrapper with unified interface. e.g. AWS IoT WebSocket dialer with automatic presign URL updater is available: AWS IoT Device SDK for Go
- Thread-safe
All functions and structs are safe to be used from multiple goroutines.
Migration guide
Examples
Reference
License
This package is licensed under Apache License Version 2.0.
# Functions
DialContext creates MQTT client using URL string.
KeepAlive runs keep alive loop.
NewReconnectClient creates a MQTT client with re-connect/re-publish/re-subscribe features.
WithAlwaysResubscribe enables or disables re-subscribe on reconnect.
WithCleanSession sets clean session flag.
WithConnStateHandler sets connection state change handler.
WithDialer sets dialer.
WithKeepAlive sets keep alive interval in seconds.
WithMaxPayloadLen sets maximum payload length of the BaseClient.
WithPingInterval sets ping request interval.
WithProtocolLevel sets protocol level.
WithReconnectWait sets parameters of incremental reconnect wait.
WithRetryClient sets RetryClient.
WithTimeout sets timeout duration of server response.
WithTLSCertFiles loads certificate files.
WithTLSConfig sets TLS configuration.
WithUserNamePassword sets plain text auth information used in Connect.
WithWill sets will message.
# Constants
Connection acceptance/rejection code.
Connection acceptance/rejection code.
Connection acceptance/rejection code.
Connection acceptance/rejection code.
MQTT 3.1.
MQTT 3.1.1 (default).
At most once delivery.
At least once delivery.
Exactly once delivery.
Connection acceptance/rejection code.
connected to the broker.
connection is unexpectedly closed.
connection is expectedly closed.
initial state.
Rejected to subscribe.
Connection acceptance/rejection code.
# Variables
ErrClosedClient means operation was requested on closed client.
ErrClosedTransport means that the underlying connection is closed.
ErrConnectionFailed means the connection is not established.
ErrInvalidPacket means that an invalid message is arrived from the broker.
ErrInvalidPacketLength means that an invalid length of the message is arrived.
ErrInvalidQoS means the QoS value is not allowed.
ErrInvalidRune means that the string has a rune not allowed in MQTT.
ErrInvalidSubAck means that the incomming SUBACK packet is inconsistent with the request.
ErrInvalidTopicFilter means that the topic filter string is invalid.
ErrKeepAliveDisabled is returned if Runned on keep alive disabled connection.
ErrNotConnected is returned if a function is called before Connect.
ErrPayloadLenExceeded means the payload length is too large.
ErrPingTimeout is returned on ping response timeout.
ErrUnsupportedProtocol means that the specified scheme in the URL is not supported.
# Structs
BaseClient is a low layer MQTT client.
BaseClientStoreDialer is a dialer wrapper which stores the latest BaseClient.
BaseStats stores base client statistics.
ConnectionError ia a error storing connection return code.
ConnectOptions represents options for Connect.
DialOptions stores options for Dial.
Error records a failed parsing.
Message represents MQTT message.
NoContextDialer is a wrapper to use Dialer of mqtt-go<1.14 as mqtt-go>=1.14 Dialer.
ReconnectOptions represents options for Connect.
RequestTimeoutError is a context deadline exceeded error caused by RetryClient.ResponseTimeout.
RetryClient queues unacknowledged messages and retry on reconnect.
RetryStats stores retry statistics.
ServeAsync is a MQTT message handler to process messages asynchronously.
ServeMux is a MQTT message handler multiplexer.
Subscription represents MQTT subscription target.
URLDialer is a Dialer using URL string.
# Interfaces
Client is the interface of MQTT client.
ClientCloser groups Client and Closer interface.
Closer is the interface of connection closer.
Dialer is an interface to create connection.
ErrorWithRetry is a error with packets which should be retransmitted.
Handler receives an MQTT message.
NoContextDialerIface is a Dialer interface of mqtt-go<1.14.
ReconnectClient is a Client with reconnect and retry features.
Retryer is an interface to control message retrying.
# Type aliases
ConnectionReturnCode represents return code of connect request.
ConnectOption sets option for Connect.
ConnState represents the status of MQTT connection.
DialerFunc type is an adapter to use functions as MQTT connection dialer.
DialOption sets option for Dial.
HandlerFunc type is an adapter to use functions as MQTT message handler.
ProtocolLevel represents MQTT protocol level.
QoS represents quality of service level.
ReconnectOption sets option for Connect.