Listeners
Serve MQTT over TCP, TLS, mutual TLS, WebSocket and secure WebSocket, optionally behind a PROXY-protocol load balancer.
A listener is a bound address plus a transport. One broker can run any number of listeners, and clients on every listener share the same sessions, subscriptions and retained messages.
| Kind | Transport | Typical port |
|---|---|---|
tcp | MQTT over TCP | 1883 |
tls | MQTT over TLS | 8883 |
ws | MQTT over WebSocket | 8083 |
wss | MQTT over WebSocket over TLS | 8084 or 443 |
Every listener has a name. It labels the per-listener metrics and appears in
GET /api/v1/status. All keys are listed in the configuration reference.
The default listener
The top-level listen key (or the ORBITMQ_LISTEN environment variable) creates a plain TCP listener named
default:
listen = "0.0.0.0:1883"When neither listen nor any [[listener]] table is configured, the broker listens on 0.0.0.0:1883. As soon as you
declare a [[listener]], that implicit default goes away; set listen as well if you still want it.
Named listeners
Each [[listener]] table adds one listener:
[[listener]]
name = "internal"
bind = "10.0.0.5:1883"
kind = "tcp" # the default
max_connections = 50000 # per listener; 0 = unlimited
handshake_timeout = 10 # seconds for PROXY header + TLS handshake + WebSocket upgradeNames must be unique (default is taken when listen is set). A listener that cannot be bound, or an invalid table,
stops the broker at start-up with an error that names the listener.
TLS
[[listener]]
name = "tls"
bind = "0.0.0.0:8883"
kind = "tls"
[listener.tls]
cert = "/etc/orbitmq/tls/server.crt" # PEM chain, leaf first
key = "/etc/orbitmq/tls/server.key" # PEM key: PKCS#8, PKCS#1 or SEC1
alpn = ["mqtt"] # optional- TLS 1.2 and TLS 1.3 are supported, using rustls with its safe defaults.
- Session resumption is enabled by default; see TLS session resumption.
- Clients that prefer the post-quantum hybrid key exchange X25519MLKEM768 get it; see Key exchange.
alpnlists the ALPN protocols to advertise. None are advertised by default;["mqtt"]is the registered name for MQTT.- Certificates are read at start-up. On Unix, a warning is logged when the private key file can be read or written by
its group or by other users; restrict it with
chmod 600.
For a quick local test, create a throw-away CA and certificates with OpenSSL:
# Test CA
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 365 \
-keyout ca.key -out ca.crt -subj '/CN=OrbitMQ test CA' \
-addext 'basicConstraints=critical,CA:TRUE' -addext 'keyUsage=critical,keyCertSign,cRLSign'
# Server certificate for localhost
openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout server.key -out server.csr -subj '/CN=localhost'
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 90 -out server.crt \
-extfile <(printf 'subjectAltName=DNS:localhost,IP:127.0.0.1\nextendedKeyUsage=serverAuth\nauthorityKeyIdentifier=keyid\n')Then connect with the CA as trust anchor:
mosquitto_sub -h localhost -p 8883 --cafile ca.crt -t 'demo/#' -vTLS session resumption
A client that reconnects can resume its previous TLS session and skip the certificate exchange. Three keys in
[listener.tls] control this, per listener:
[listener.tls]
cert = "/etc/orbitmq/tls/server.crt"
key = "/etc/orbitmq/tls/server.key"
session_resumption = true # the default
session_cache_size = 16384 # the default; 0 = no session-ID cache
tls12_tickets = false # the default; env ORBITMQ_TLS_TLS12_TICKETS- TLS 1.3 resumes with session tickets. The broker sends one ticket per handshake, together with the CONNACK, and each resumption brings a new ticket. A TLS 1.3 resumption always runs a fresh key exchange.
- TLS 1.2 resumes through the in-memory session-ID cache of
session_cache_sizeentries.0turns the cache off, so TLS 1.2 clients then run a full handshake every time (unlesstls12_tickets = true). TLS 1.2 session tickets are off by default: a TLS 1.2 client that asks for one gets an empty ticket and resumes by session ID. tls12_tickets = trueissues session tickets to TLS 1.2 clients too, so they can resume without a cache entry on the broker (stateless resumption, useful when more TLS 1.2 clients reconnect than the cache holds). The cost is forward secrecy: TLS 1.2 resumption skips the key exchange, so anyone who obtains a ticket key while it is still kept can decrypt the recorded TLS 1.2 sessions that were started or resumed with its tickets. TLS 1.3 tickets are not affected.- Ticket keys belong to one listener and are kept in memory only, never written to disk. A new key is used every 6 hours, and a ticket is accepted for up to 12 hours, after which its key is erased. After a restart, earlier tickets are no longer accepted and clients run a full handshake.
- 0-RTT (early data) is always off, because early data can be replayed. It cannot be enabled.
session_resumption = falseturns tickets and the session-ID cache off: every connection runs a full handshake.
ORBITMQ_TLS_TLS12_TICKETS=true|false sets tls12_tickets on every listener that has a [listener.tls] table.
Key exchange
TLS key exchange uses X25519, P-256, P-384 or the post-quantum hybrid X25519MLKEM768 (X25519 combined with
ML-KEM-768). key_exchange decides how the group is chosen, per listener:
[listener.tls]
cert = "/etc/orbitmq/tls/server.crt"
key = "/etc/orbitmq/tls/server.key"
key_exchange = "client-preferred" # the default; or "hybrid-preferred"key_exchange | Group chosen |
|---|---|
"client-preferred" (default) | The client's most preferred group among those above. A client that prefers X25519MLKEM768 gets it; one that prefers X25519 gets X25519. |
"hybrid-preferred" | X25519MLKEM768 whenever the client offers it at all, even below a classical group, and the classical groups otherwise. |
With "hybrid-preferred", a client that lists the hybrid but sent only a classical key share is asked for a hybrid
one, which costs an extra round trip. The hybrid exchange is also more expensive than X25519 alone, so this setting
costs some handshake throughput; choose it when protection of recorded traffic against future quantum computers
matters more than handshake rate. The hybrid group exists only in TLS 1.3, so TLS 1.2 clients always use a classical
group.
ORBITMQ_TLS_KEY_EXCHANGE=client-preferred|hybrid-preferred sets key_exchange on every listener that has a
[listener.tls] table. Any other value is a configuration error.
Mutual TLS
Add client_ca to verify client certificates against a CA bundle:
[[listener]]
name = "devices"
bind = "0.0.0.0:8884"
kind = "tls"
[listener.tls]
cert = "/etc/orbitmq/tls/server.crt"
key = "/etc/orbitmq/tls/server.key"
client_ca = "/etc/orbitmq/tls/clients-ca.crt"
require_client_cert = trueclient_ca | require_client_cert | Behaviour |
|---|---|---|
| unset | false | No client certificate is requested. |
| set | false | A certificate is requested and verified when presented; clients without one are accepted. |
| set | true | Clients without a valid certificate fail the TLS handshake. |
| unset | true | Configuration error. |
A client certificate signed by the test CA above:
openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout client.key -out client.csr -subj '/CN=device-1'
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 90 -out client.crt \
-extfile <(printf 'extendedKeyUsage=clientAuth\nauthorityKeyIdentifier=keyid\n')
mosquitto_sub -h localhost -p 8884 --cafile ca.crt --cert client.crt --key client.key -t 'demo/#' -vCertificates and MQTT identity
On its own, a verified client certificate controls who may connect to the listener; it is not turned into an MQTT
user name, and password authentication and ACL rules that use %u work with the user
name sent in CONNECT. Add an x509 authentication backend
to authenticate clients by their certificate and use its CN, DN or SHA-256 fingerprint as the user name.
WebSocket
[[listener]]
name = "websocket"
bind = "0.0.0.0:8083"
kind = "ws"
[listener.ws] # optional; these are the defaults
path = "/mqtt" # must start with "/"
max_frame_size = 16777216 # bytes (16 MiB)
max_handshake_size = 8192 # bytes (8 KiB)
require_subprotocol = true- Clients connect to
ws://host:8083/mqtt. Query strings are ignored; any other path gets HTTP404. - Clients must offer the
mqttWebSocket subprotocol, as the MQTT specification requires.mqttv3.1, which some MQTT 3.1 libraries offer instead, is also accepted, and is selected only when the client does not offermqtt. A client that offers neither is refused with HTTP400; withrequire_subprotocol = falseit is accepted without a subprotocol. - MQTT packets may span WebSocket frames, and one frame may carry several packets. Text frames close the connection, as the specification requires.
- A data frame larger than
max_frame_sizecloses the connection with close code 1009 (message too big). An upgrade request larger thanmax_handshake_sizegets HTTP431. Both sizes must be non-zero.
For example, with MQTT.js in a browser or Node.js:
import mqtt from 'mqtt';
const client = mqtt.connect('ws://localhost:8083/mqtt', { protocolVersion: 5 });
client.on('connect', () => client.subscribe('demo/#'));
client.on('message', (topic, payload) => console.log(topic, payload.toString()));Secure WebSocket
wss combines both tables:
[[listener]]
name = "websocket-tls"
bind = "0.0.0.0:8084"
kind = "wss"
[listener.tls]
cert = "/etc/orbitmq/tls/server.crt"
key = "/etc/orbitmq/tls/server.key"
[listener.ws]
path = "/mqtt"Clients connect to wss://host:8084/mqtt. Mutual TLS works on wss listeners in the same way as on tls.
Behind a load balancer (PROXY protocol)
When a TCP load balancer such as HAProxy, NGINX (stream) or a cloud network load balancer sits in front of the broker, enable the PROXY protocol so the broker sees the real client address:
[[listener]]
name = "behind-lb"
bind = "0.0.0.0:1883"
proxy_protocol = true
trusted_proxies = ["10.0.0.0/24", "192.0.2.10"] # the load balancers- Versions 1 (text) and 2 (binary) are accepted. The header must arrive first, before any TLS or WebSocket
handshake, so it works with every
kind. - The client address from the header replaces the socket address, for example in the
peerfield of the admin API. ALOCALorUNKNOWNheader keeps the socket's own address. - A connection without a valid header is closed. Only enable this on listeners that are reachable exclusively through the proxy.
trusted_proxieslists the load balancers (IP addresses or CIDR blocks) allowed to send the header. A connection from any other peer is closed before the header is read, so a client that reaches the listener directly cannot choose the address the broker sees. Leave it empty only when the network already guarantees that; the broker then logs a warning at start-up that any peer may send the header. Settingtrusted_proxieswithoutproxy_protocol = trueis a configuration error.
Example HAProxy backend:
backend orbitmq
mode tcp
server broker1 10.0.0.5:1883 send-proxy-v2Getting started
Build OrbitMQ from source, run it, and publish your first messages over MQTT 3.1.1 and 5.0.
Authentication
The ordered authentication chain (password file, X.509, JWT, HTTP, PostgreSQL, MySQL, Redis, MongoDB), its allow / deny / ignore cascade, caching, failure policy, and runtime changes from the admin API and the dashboard.