Expand description
Per-delivery context fields exposed to handlers.
AmqpContext carries the AMQP delivery metadata that is not part of the payload or the
headers. Request it in a handler by typing the context parameter as
Context<'_, AmqpContext> and read individual fields with the zero-sized keys in keys.
The prelude carries the keys but not the context type, so import that from here. The
AmqpContext page
shows both forms in a service.
§Examples
use ruststream_lapin::context::AmqpContext;
use ruststream_lapin::context::keys::RoutingKey;
use ruststream_lapin::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
}
#[subscriber(RabbitQueue::new("orders"))]
async fn audit(order: &Order, ctx: &mut Context<'_, AmqpContext>) -> HandlerOutcome {
tracing::info!(order.id, routing_key = ctx.context(RoutingKey), "audited");
HandlerOutcome::ack()
}
fn app() -> RustStream {
let broker = LapinBroker::new("amqp://localhost:5672");
RustStream::new(AppInfo::new("audit", "0.1.0")).with_broker(broker, |b| {
b.include(audit);
})
}Modules§
- keys
- Zero-sized
Fieldkeys reading oneAmqpContextfield each.
Structs§
- Amqp
Context - Native AMQP delivery metadata, built once per delivery.