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

下面显示的是英文原文。

Negative acknowledgement

MQTT has no negative acknowledgement, so retry answers AckError::Unsupported and leaves the delivery unacknowledged.

A nack with requeue set is what retry asks for. The transport has no packet for it, so the delivery stays unacknowledged on the server, which redelivers it when a persistent session resumes. The runtime logs the unsupported answer as a warning and does not send the message again by itself. A handler that wants the delivery back within the session answers retry_after. A nack without requeue is a drop, and it acknowledges.

Example​

A job that is not ready to run is answered with retry, and the runtime sees one call.

/// A job id of zero is not ready to run. `retry` asks for a negative acknowledgement, which MQTT
/// does not have: the delivery stays unacknowledged, and the server sends it again when a
/// persistent session resumes.
#[subscriber(MqttTopic::new("jobs/run"))]
async fn run(job: &Job) -> HandlerOutcome {
if job.id == 0 {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}

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