Typed extractors
Receive message metadata, DI services, local state, and payload through handler parameters.
Extractors turn framework-owned delivery state into the Rust values a handler requests. Metadata and services are obtained without consuming the body; a payload-owning extractor, if present, must be the final parameter.
Metadata and payload order#
Use the following method in place of the first application's method inside #[queue_service] impl OrderWorker. DeliveryContext and RetryCount do not consume the body; Json<OrderCreated> resolves last. Import the types from lilyrs::queue.
#[queue("orders.created", version = 1, content = "json")]
async fn created(
&self,
context: lilyrs::queue::DeliveryContext,
_retry: lilyrs::queue::RetryCount,
Json(event): Json<OrderCreated>,
) -> Result<(), QueueHandlerError> {
let _event_id = context.event_id();
println!("{}", event.order_id);
Ok(())
}Parts extractors run in declaration order. If one rejects, later extractors and the handler are not called; the entered middleware prefix follows normal error unwinding. A handler supports at most 16 extractors and one terminal payload. A type's trait implementation determines its role, rather than whether its name happens to be Json.
Metadata, services, and local state#
| Extractor | Value provided |
|---|---|
DeliveryContext |
Queue/exchange/routing, event, schema, content, retry, and redelivery metadata |
EventId, SchemaVersion, ContentKind |
One field from the contract |
RetryCount, Redelivered |
Framework retry count and the separate broker redelivery flag |
DeliveryHeaders, DeliveryProperties |
Bounded headers and allowlisted AMQP properties |
DeliveryCancellation, DeliveryDeadline |
Read-only execution signal and normal pipeline cutoff |
Service<T> |
DI service resolved through the active delivery scope |
Local<T>, Option<Local<T>> |
Typed delivery-local state supplied by an earlier stage |
These values carry neither a broker channel nor ACK authority. Receiving a reply_to property does not create an automatic request/reply service. DeliveryCancellation and DeliveryDeadline provide read-only access to framework execution control; your application explicitly connects them to other subsystem contexts.
Choose a payload extractor#
| Extractor | Content contract | Behavior |
|---|---|---|
Json<T> |
json |
DeserializeOwned + Send; malformed JSON is permanent failure |
TextPayload |
text |
Owned UTF-8 String; invalid encoding is permanent failure |
BinaryPayload |
binary |
Bounded body bytes |
RawDelivery |
A valid explicit content token | Body and metadata; not an ACK/NACK object |
Custom FromDelivery |
Custom contract | Application decoder with sole body authority |
Body authority is consumed once. Combining Json<T> and RawDelivery in one method, or placing metadata after the payload, is invalid. Choosing raw body access does not remove envelope validation or transport size bounds.
Optional values and rejection#
Option<E> applies only when E implements OptionalFromDeliveryParts. Option<Local<T>> can represent an absent local value as None; Option<Service<T>> or Option<Json<T>> is not a general mechanism for ignoring errors. A missing required Local<T> produces a retryable error.
Use FromDeliveryParts to build custom values from metadata, DI, or local state, and FromDelivery for body decoding. Deserializing JSON into a Rust type is separate from validating business data.
Sources for this page v0.1.0
This guide is based on the reviewed framework commit.