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

下面显示的是英文原文。

create_if_missing

create_if_missing() creates the queue at startup when it is missing; a .fifo name creates a FIFO queue, and a dead-letter queue is created too.

The subscription calls CreateQueue when it opens and the account does not have the queue yet. Without the step, a missing queue stops the service at startup. A name that ends in .fifo creates a FIFO queue with content-based deduplication. A dead-letter queue the registration declares is created the same way. Every other attribute of a new queue keeps the SQS default, a 30 second visibility timeout among them. The step needs the sqs:CreateQueue permission. It suits a local stack and a test; production queues are usually managed as infrastructure. In process every queue a service names exists already, so the step shows its effect in a live test. The step is on SqsQueue, and on the mount chain through SqsSubscription::create_if_missing, as in the example.

Example​

A drafts queue the service opens itself on a fresh stack.

/// Reads drafts from a queue the service opens itself on a fresh stack.
#[subscriber(SqsQueue)]
async fn review(draft: &Draft) -> HandlerOutcome {
tracing::info!(draft.id, "draft reviewed");
HandlerOutcome::ack()
}

fn service(broker: SqsBroker, queue: String) -> impl App<State = ()> {
RustStream::new(AppInfo::new("drafts", "0.1.0")).with_broker(broker, |b| {
b.include(review.name(queue).create_if_missing());
})
}