跳到主要内容
本页尚未翻译

下面显示的是英文原文。

Shared subscription

A shared subscription hands each message to one member of a group, so boards that run the same service share the work.

shared(group) on MqttTopic or MqttFilter subscribes through $share/<group>/<filter>, an MQTT 5 feature. The server gives each matching message to one subscription of the group instead of to every one. The group name must not be empty and must not contain /, + or #; the descriptor refuses it when the app starts.

The server sends no retained message to a shared subscription when it joins. A retry copy of a delivery goes to the plain topic: the $share prefix is a name for subscribing, and a publish to it would reach a topic of that literal spelling.

Example​

Every board runs this service, and the server gives each job to one of them.

/// Every board runs this service; the server gives each job to one of them.
#[subscriber(MqttTopic::new("jobs/render").shared("renderers"))]
async fn render(job: &Job) -> HandlerOutcome {
let _ = job.id;
HandlerOutcome::ack()
}

#[ruststream::app(runtime = embassy)]
fn app(broker: MqttBroker) -> EmbeddedApp<impl Mounts> {
EmbeddedApp::new().with_broker(broker, |b| b.include(render))
}