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.
- Macros
- Manual
/// 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))
}
/// 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.
struct Run;
impl Handle<Job> for Run {
fn handle(
&self,
job: &Job,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
ready(if job.id == 0 {
Err(HandlerOutcome::retry())
} else {
Ok(())
})
}
}
fn app(broker: MqttBroker) -> EmbeddedApp<impl Mounts> {
EmbeddedApp::new().with_broker(broker, |b| {
b.include(
subscriber("jobs/run", Run)
.map_source(|_| MqttTopic::new("jobs/run"))
.build(),
)
})
}