Ниже показан английский оригинал.
Batches
A slice handler gets one ReceiveMessage worth of messages; batch(n) becomes MaxNumberOfMessages, capped at ten.
A handler over &[T] is a batch handler, and batch(n) at the mount site is its largest batch.
ReceiveMessage returns several messages per call, so the size becomes its MaxNumberOfMessages and one receive is one batch.
Nothing buffers in the service.
A batch holds what the queue had at that moment, so a quiet queue yields batches of one.
A batch is never empty: a long poll that runs out hands the handler nothing.
SQS returns at most ten messages per receive, so a larger size becomes ten, and the subscription logs that once.
One outcome settles every message of the batch.
A Vec<HandlerOutcome> settles message i with outcome i.
A single-message handler also receives up to ten messages per call, because SQS bills per request, and gets them one at a time; workers(n) decides how many run at once.
In the manual form the body is an impl Handle<[T]>, where Ok(()) acknowledges the batch and Err(outcomes) settles each message.
Example
Three orders waiting on the queue arrive in one call; twelve arrive as ten and two.
- Macros
- Manual
/// A batch handler: the slice is one `ReceiveMessage` worth of orders, settled as a whole. It
/// holds at most the size the mount site names, and as few as one when that is all the queue
/// had at the moment of the call.
#[subscriber(SqsQueue::new("orders-batches"))]
async fn reconcile(orders: &[Order]) -> HandlerOutcome {
tracing::info!(count = orders.len(), "reconciled a batch of orders");
HandlerOutcome::ack()
}
/// A batch handler: the slice is one `ReceiveMessage` worth of orders, and `Ok` settles it as a
/// whole. It holds at most the size the mount site names, and as few as one when that is all the
/// queue had at the moment of the call.
struct Reconcile;
impl Handle<[Order]> for Reconcile {
fn handle(
&self,
orders: &[Order],
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), Vec<HandlerOutcome>>> {
tracing::info!(count = orders.len(), "reconciled a batch of orders");
ready(Ok(()))
}
}