Client Configuration¤
This configuration structure is either a amqtt.contexts.ClientConfig or a python dictionary with identical structure
when instantiating amqtt.broker.MQTTClient or as a yaml formatted file passed to the amqtt_pub script.
If not specified, the MQTTClient() will be started with the default ClientConfig(), as represented in yaml format:
---
keep_alive: 10
ping_delay: 1
default_qos: 0
default_retain: false
auto_reconnect: true
connection_timeout: 60
reconnect_retries: 2
reconnect_max_interval: 10
cleansession: true
broker:
uri: "mqtt://127.0.0.1"
plugins:
amqtt.plugins.logging_amqtt.PacketLoggerPlugin:
ClientConfig
dataclass
¤
Bases: Dictable
Structured configuration for a broker. Can be passed directly to amqtt.broker.Broker or created from a dictionary.
auto_reconnect
class-attribute
instance-attribute
¤
auto_reconnect: bool | None = True
Enable or disable auto-reconnect if connection with the broker is interrupted.
broker
class-attribute
instance-attribute
¤
broker: ConnectionConfig | None = None
Deprecated Configuration for connecting to the broker. Use connection field instead.
check_hostname
class-attribute
instance-attribute
¤
check_hostname: bool | None = True
If establishing a secure connection, should the hostname of the certificate be verified.
cleansession
class-attribute
instance-attribute
¤
cleansession: bool | None = True
Upon reconnect, should subscriptions be cleared. Can be overridden by MQTTClient.connect
connection
class-attribute
instance-attribute
¤
connection: ConnectionConfig = ConnectionConfig()
Configuration for connecting to the broker. See
ConnectionConfig for more information.
connection_timeout
class-attribute
instance-attribute
¤
connection_timeout: int | None = 60
The number of seconds before a connection times out
default_qos
class-attribute
instance-attribute
¤
default_qos: int | None = QOS_0
Default QoS for messages published.
default_retain
class-attribute
instance-attribute
¤
default_retain: bool | None = False
Default retain value to messages published.
keep_alive
class-attribute
instance-attribute
¤
keep_alive: int | None = 10
Keep-alive timeout sent to the broker.
ping_delay
class-attribute
instance-attribute
¤
ping_delay: int | None = 1
Auto-ping delay before keep-alive timeout. Setting to 0 will disable which may lead to broker disconnection.
plugins
class-attribute
instance-attribute
¤
plugins: dict[str, Any] | list[dict[str, Any]] | None = {
"amqtt.plugins.logging_amqtt.PacketLoggerPlugin": {}
}
The dictionary has a key of the dotted-module path of a class derived from BasePlugin; the value is
a dictionary of configuration options for that plugin. See custom plugins for
more information. list[str | dict[str,Any]] is deprecated but available to support legacy use cases.
reconnect_max_interval
class-attribute
instance-attribute
¤
reconnect_max_interval: int | None = 10
Maximum seconds to wait before retrying a connection.
reconnect_retries
class-attribute
instance-attribute
¤
reconnect_retries: int | None = 2
Number of reconnection retry attempts. Negative value will cause client to reconnect indefinitely.
topics
class-attribute
instance-attribute
¤
topics: dict[str, TopicConfig] | None = {}
Specify the topics and what flags should be set for messages published to them.
will
class-attribute
instance-attribute
¤
will: WillConfig | None = None
Message, topic and flags that should be sent to if the client disconnects. See
WillConfig for more information.
TopicConfig
dataclass
¤
Bases: Dictable
Configuration of how messages to specific topics are published.
The topic name is specified as the key in the dictionary of the `ClientConfig.topics.
WillConfig
dataclass
¤
Bases: Dictable
Configuration of the 'last will & testament' of the client upon improper disconnection.
ConnectionConfig
dataclass
¤
Bases: Dictable
Properties for connecting to the broker.
cadata
class-attribute
instance-attribute
¤
cadata: str | None = None
The certificate to verify the broker's authenticity in an ASCII string format of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates.
cafile
class-attribute
instance-attribute
¤
cafile: str | Path | None = None
Path to a file of concatenated CA certificates in PEM format to verify broker's authenticity. See Certificates for more info.
capath
class-attribute
instance-attribute
¤
capath: str | Path | None = None
Path to a directory containing one or more CA certificates in PEM format, following the OpenSSL-specific layout.
certfile
class-attribute
instance-attribute
¤
certfile: str | Path | None = None
Full path to file in PEM format containing the client's certificate (as well as any number of CA certificates needed to establish the certificate's authenticity.)
keyfile
class-attribute
instance-attribute
¤
keyfile: str | Path | None = None
Full path to file in PEM format containing the client's private key associated with the certfile.
uri
class-attribute
instance-attribute
¤
uri: str | None = 'mqtt://127.0.0.1:1883'
URI of the broker
Example¤
A more expansive ClientConfig in equivalent yaml format:
keep_alive: 10
ping_delay: 1
default_qos: 0
default_retain: false
auto_reconnect: true
reconnect_max_interval: 5
reconnect_retries: 10
topics:
topic/subtopic:
qos: 0
topic/other:
qos: 2
retain: true
will:
topic: will/messages
message: "client ABC has disconnected"
qos: 1
retain: false
broker:
uri: 'mqtt://localhost:1883'
cafile: '/path/to/ca/file'
plugins:
- amqtt.plugins.logging_amqtt.PacketLoggerPlugin: