Queue
Creates and manages Cloudflare Queues for reliable message delivery between workers.
Props
Name of the queue.
${app}-${stage}-${id}
Settings for the queue.
Delay in seconds before message delivery. Queue will not deliver messages until this time has elapsed.
Whether delivery is paused. If true, the queue will not deliver messages to consumers.
Period in seconds to retain messages. Messages will be automatically deleted after this time.
Dead letter queue for failed messages.const dlq = await Queue("failed-tasks");
const queue = await Queue("tasks", {
dlq: dlq
});
Whether to delete the queue when the resource is removed from Alchemy.
Whether to adopt an existing queue with the same name if it exists.
Output
The unique ID of the queue.
Time when the queue was created.
Type identifier for the binding.
Examples
Basic Queue
const queue = await Queue("tasks", {
name: "task-queue"
});
Queue with Custom Settings
const queue = await Queue("delayed-queue", {
name: "delayed-queue",
settings: {
deliveryDelay: 30,
messageRetentionPeriod: 86400
}
});
Queue with Dead Letter Queue
const dlq = await Queue("dlq-queue");
const mainQueue = await Queue("main-queue", {
dlq: dlq
});
Queue Producer and Consumer
const processingQueue = await Queue("processing-queue");
const worker = await Worker("processor", {
entrypoint: "./src/processor.ts",
bindings: {
QUEUE: processingQueue
},
eventSources: [{
queue: processingQueue,
settings: {
batchSize: 25,
maxConcurrency: 5,
maxRetries: 3,
maxWaitTimeMs: 1500,
retryDelay: 45,
deadLetterQueue: "failed-processing"
}
}]
});