Mercurio

An MQTT broker, client library and command-line client written in Rust on top of Tokio. It speaks MQTT 3.1, 3.1.1 and 5.0, and reads mosquitto's password and ACL files, so existing setups move over with little change.

What's in the box

ComponentWhat it is
mercuriodThe broker daemon. Configured with a TOML file, runs as a systemd service.
recadoCommand-line client: recado pub and recado sub.
mercurioctlAdministers a running broker: clients, bans, retained messages, subscriptions, the log level, reloads and dynamic security.
mercurio-clientAsync Rust client library.
mercurio-serverThe broker as a library, to embed in your own program or extend with custom authentication.
mercurio-storageStorage for sessions, retained messages, wills and queued messages, in memory, SQLite or PostgreSQL.
mercurio-core, mercurio-packetsShared types and the encoding of every MQTT packet, for all three protocol versions.
mercurio-scramSCRAM-SHA-256 messages and key derivation, shared by the client and the broker.

Quick start

Build everything, start the broker with its defaults (plain MQTT on 127.0.0.1:1883, state in memory), and exchange a message:

cargo build --release

./target/release/mercuriod

# In a second terminal
./target/release/recado sub -t 'sensors/#' -T

# In a third
./target/release/recado pub -t sensors/kitchen -m 21.5 -q 1

The subscriber prints sensors/kitchen 21.5. Any MQTT client works with the broker, mosquitto's included:

mosquitto_sub -V mqttv5 -t 'sensors/#' -v

Features

Protocol

Broker

Where to go next

Installing & runningBuild, run as a service, signals. Configuration referenceEvery option of the TOML file. Authentication & accessPasswords, ACLs, TLS, dynamic security. ListenersTLS, WebSocket, Unix sockets, mount points. BridgesForward topics to and from other brokers. OperationsPersistence, limits, statistics, logs. AdministrationClients, bans and reloads at runtime, with mercurioctl. Rust client libraryConnect, publish and subscribe from Rust. WebAssembly pluginsExtend the broker with sandboxed components. Migrating from mosquittoOption by option.

Performance

Measured on one 16-core machine with the load generator in mercurio-client/examples/bench.rs, against mosquitto 2.0.18 under the same load:

ScenarioMercuriomosquitto
QoS 0, 10 publishers to 1 subscriber271k msg/s108k msg/s
QoS 1, 10 publishers to 1 subscriber94k msg/s28k msg/s
QoS 0, 1 publisher to 50 subscribers1.1M deliveries/s110k deliveries/s
QoS 1 round trip at 1,000 msg/s, p50 / p99139 / 245 µs249 / 573 µs

mosquitto runs on one thread, while Mercurio uses every core, which accounts for much of the difference. Run the scenarios on your own hardware with:

cargo run --release --example bench -- <port> [fan-in-qos0|fan-in-qos1|fan-out|latency]