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

下面显示的是英文原文。

MqttFilter

MqttFilter subscribes to every topic its wildcards match: + matches one level and # matches the rest.

One filter reads many topics, so it addresses none of them. A retry copy cannot go to a filter, and the mount site names where it goes. The delivery keeps the topic it was published to, and MqttMessage::topic returns it. A filter that is not a valid topic filter is refused when the app starts.

qos and shared work as on MqttTopic. A definition written #[subscriber(MqttFilter)] takes its filter from the name given at the mount site.

Example​

Every sensor of the first floor reports on a topic of its own.

/// Every sensor of the first floor reports on a topic of its own.
#[subscriber(MqttFilter::new("floor-1/+/temp"))]
async fn log(reading: &Reading) -> HandlerOutcome {
let _ = reading.celsius;
HandlerOutcome::ack()
}

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