Microservices
MQTT
The MQTT v5 link, a topic per pattern with shared subscriptions, Response Topic and Correlation Data.
The MQTT link needs an MQTT v5 broker. Each pattern is a topic, the payload is the body, headers are user properties, and replies use the Response Topic and Correlation Data properties.
app.bind(ulo_rpc::Server::new(ulo_rpc_mqtt::Mqtt::url("mqtt://broker:1883")));Settings
| Method | Effect |
|---|---|
Mqtt::url(url) | mqtt:// or mqtts:// |
qos(QoS) | QoS::AtMostOnce, QoS::AtLeastOnce (default) or QoS::ExactlyOnce |
group(name) | the shared-subscription group. Defaults to the application's root module's full type path |
codec(Codec) | JSON by default; Codec::Cbor carries raw bytes |
with_handle(Handle) | the tokio runtime, when the link is built outside one |
Behaviour
- Competing consumers. A server subscribes through
$share/<group>/<topic>. A CONNACK that announces no shared-subscription support fails the server's start, naming the setting, when a pattern reaches one instance, as every request and every event left at the default does. A server whose patterns are all events declaredevery_instancestarts. The refusal is tested against a scripted broker whose CONNACK announces no shared subscriptions. Mosquitto 2.0.18, the conformance suite's broker, supports them. - Events. An event left at the default goes through the shared subscription and is handled by one instance. An event declared
#[ulo_rpc::event("pattern", every_instance)]is subscribed through the plain topic filter and reaches every instance. - Misses. A PUBACK or PUBREC with reason code 0x10 ("No matching subscribers") maps to
unavailablewith the reasonno_destination, at QoS 1 and 2. At QoS 0 nothing is acknowledged, so the caller sees its ownTimeout. - Frame limit. The maximum packet size from the broker's CONNACK.
- In-flight limit. Work over
max_inflight(1,024 unset) is refusedunavailablewith aRetryAfterdetail, as on TCP, UDP, NATS and Redis, and is not held at the broker. Both sides announce a Receive Maximum of 65,535. Mosquitto applies its ownmax_inflight_messages(20 unset) otherwise. - Lost connection. A call waiting when the client's connection drops fails
Unavailable, since a clean session loses what reached the reply topic meanwhile. - TLS.
mqtts://trusts the platform's root certificates, read once per link. A store that cannot be read or holds no root fails a server'sbind, and each client call failsInternalwith the reasonmisconfigured_link. - Streams. A streamed request opens with the user property
ulo-t: openand is answeredulo-t: opened. Items, end andcanceltravel onulo/rpc/control, which every instance subscribes to outside the shared subscription. - Drain. The server unsubscribes and returns once the broker has acknowledged each UNSUBSCRIBE. A request can still be lost at shutdown if more requests are outstanding to the instance than the broker's flow control allows. Its caller then sees its own
Timeout.
Mosquitto and held work
The link does not hold work at the broker, because MQTT 5 section 4.8.2 only recommends that a broker pass an unacknowledged shared-subscription message to another member when its holder's session ends. Mosquitto 2.0.18 does not: in a probe of 60 runs, no unacknowledged QoS 1 message reached another member once its holder was gone. Another broker may behave differently.