2025-05-21 13:53:46 +00:00
# broker
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
`amqtt` is a command-line script for running a MQTT 3.1.1 broker.
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Usage
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
`amqtt` usage:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```
amqtt --version
amqtt (-h | --help)
amqtt [-c < config_file > ] [-d]
```
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Options
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
- `--version` - amqtt version information
- `-h, --help` - Display `amqtt_sub` usage help
- `-c` - Set the YAML configuration file to read and pass to the client runtime.
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Configuration
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
Without the `-c` argument, the broker will run with the following, default configuration:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```yaml
listeners:
2025-05-22 01:59:12 +00:00
default:
type: tcp
bind: 0.0.0.0:1883
2025-05-21 13:53:46 +00:00
sys_interval: 20
auth:
2025-05-22 01:59:12 +00:00
allow-anonymous: true
2025-05-21 13:53:46 +00:00
plugins:
2025-05-22 01:59:12 +00:00
- auth_file
- auth_anonymous
2025-05-21 13:53:46 +00:00
```
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
Using the `-c` argument allows for configuration with a YAML structured file. The following sections contain the available configuration elements:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Field Descriptions
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
### `listeners`
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
Defines network listeners for the MQTT server (list).
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
#### `<interface name>`
2025-05-22 01:59:12 +00:00
2025-05-21 16:37:02 +00:00
`default` for parameters used across all interfaces _or_ name for the specific interface (mapping).
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
Each entry supports these parameters:
2025-05-22 01:59:12 +00:00
- `bind` (string, _required_ )
2025-05-21 13:53:46 +00:00
Address and port to bind to, in the form `host:port` (e.g., `0.0.0.0:1883` ).
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `type` (string, _required_ )
2025-05-21 13:53:46 +00:00
Protocol type. Typically `"tcp"` or `"ws"` .
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `max-connections` (integer, _required_ )
2025-05-21 13:53:46 +00:00
Maximum number of clients that can connect to this interface
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `ssl` (string, _optional, default: `off`_ )
2025-05-21 16:37:02 +00:00
Disable (`off`) SSL/TLS or enable (`on`) with one of `cafile` , `capath` , `cadata` or `certfile` /`keyfile`.
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `cafile` (string, _optional_ )
2025-05-21 13:53:46 +00:00
Path to a file of concatenated CA certificates in PEM format. See [Certificates ](https://docs.python.org/3/library/ssl.html#ssl-certificates ) for more info.
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `capath` (string, _optional_ )
2025-05-21 13:53:46 +00:00
Path to a directory containing several CA certificates in PEM format, following an [OpenSSL specific layout ](https://docs.openssl.org/master/man3/SSL_CTX_load_verify_locations/ ).
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `cadata` (string, _optional_ )
2025-05-21 13:53:46 +00:00
Either an ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `certfile` (string, _optional_ )
2025-05-21 13:53:46 +00:00
Path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate's authenticity
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `keyfile` (string, _optional_ )
2025-05-21 13:53:46 +00:00
A file containing the private key. Otherwise the private key will be taken from certfile as well
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
### timeout-disconnect-delay
2025-05-22 01:59:12 +00:00
Client disconnect timeout without a keep-alive (integer, _optional_ )
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
### plugins
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
Entry points for optional functionality (_list of strings_); included plugins are:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
- `auth_file` – Enables file-based authentication
- `auth_anonymous` – Enables anonymous access
- `event_logger_plugin`
- `packet_logger_plugin`
- `topic_taboo`
- `topic_acl`
- `broker_sys`
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
### auth
2025-05-20 23:40:56 +00:00
2025-05-21 16:37:02 +00:00
Authentication and authorization settings (mapping).
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `allow-anonymous` (boolean, _optional for `auth_anonymous` plugin_)
2025-05-21 16:37:02 +00:00
Allow (`true`) or prevent (`false`) anonymous client to connections.
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
- `password-file` (string, _required for `auth_file` plugin_)
2025-05-21 16:37:02 +00:00
Path to file which includes `username:password` pair, one per line. The password should be encoded using sha-512 with `mkpasswd -m sha-512` or:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```python
import sys
from getpass import getpass
from passlib.hash import sha512_crypt
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
passwd = input() if not sys.stdin.isatty() else getpass()
print(sha512_crypt.hash(passwd))
```
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
### sys-interval
2025-05-20 23:40:56 +00:00
2025-05-22 01:59:12 +00:00
Interval in seconds to publish system statistics to `$SYS` topics (integer, _optional for `broker_sys` plugin, defaults to TBD_).
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Configuration example
```yaml
listeners:
2025-05-22 01:59:12 +00:00
default:
max-connections: 500
type: tcp
my-tcp-1:
bind: 127.0.0.1:1883
my-tcp-2:
bind: 1.2.3.4:1883
max-connections: 1000
my-tcp-tls-1:
bind: 127.0.0.1:8883
ssl: on
cafile: /some/cafile
my-ws-1:
bind: 0.0.0.0:9001
type: ws
my-wss-1:
bind: 0.0.0.0:9003
type: ws
ssl: on
certfile: /some/certfile
keyfile: /some/key
2025-05-21 13:53:46 +00:00
plugins:
2025-05-22 01:59:12 +00:00
- auth_file
- broker_sys
2025-05-21 13:53:46 +00:00
timeout-disconnect-delay: 2
auth:
2025-05-22 01:59:12 +00:00
password-file: /some/passwd_file
2025-05-21 13:53:46 +00:00
```
The `listeners` section defines 5 bindings:
2025-05-22 01:59:12 +00:00
- `my-tcp-1` : an unsecured TCP listener on port 1883 allowing `500` clients connections simultaneously
- `my-tcp-2` : an unsecured TCP listener on port 1884 allowing `1000` client connections
- `my-tcp-ssl-1` : a secured TCP listener on port 8883 allowing `500` clients connections simultaneously
- `my-ws-1` : an unsecured websocket listener on port 9001 allowing `500` clients connections simultaneously
- `my-wss-1` : a secured websocket listener on port 9003 allowing `500`
2025-05-20 23:40:56 +00:00
The plugins section enables:
2025-05-22 01:59:12 +00:00
- `auth_file` plugin, requiring `password-file` to be defined in the `auth` section
- `broker_sys` plugin, requiring `sys_interval` to be defined
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
Authentication allows anonymous logins and password file based authentication. Password files are required to be text files containing user name and password in the form of:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```
username:password
```
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
where `password` should be the encrypted password. Use the `mkpasswd -m sha-512` command to build encoded passphrase. Password file example:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```
# Test user with 'test' password encrypted with sha-512
test:$6$l4zQEHEcowc1Pnv4$HHrh8xnsZoLItQ8BmpFHM4r6q5UqK3DnXp2GaTm5zp5buQ7NheY3Xt9f6godVKbEtA.hOC7IEDwnok3pbAOip.
```