Queue
The Queue component lets you add a Cloudflare Queue to
your app.
Create a Queue
const queue = new sst.cloudflare.Queue("MyQueue");Subscribe to the Queue
Create a worker file that exposes a default handler for queue messages:
export default { async queue(batch, env) { for (const message of batch.messages) { console.log("Processing message:", message.body); } },};Subscribe to the queue with a consumer worker.
queue.subscribe("consumer.ts");Link to the Queue
You can link other workers to the queue.
new sst.cloudflare.Worker("MyWorker", { handler: "producer.ts", link: [queue], url: true,});Subscribe with full worker props
const bucket = new sst.cloudflare.Bucket("MyBucket");
queue.subscribe({ handler: "consumer.ts", link: [bucket],});Constructor
new Queue(name, args?, opts?)Parameters
-
namestring -
args?QueueArgs -
opts?ComponentResourceOptions
QueueArgs
dlq?
Type Object
The dead letter queue to send messages that fail processing.
When dlq is configured, dlq.queue is required.
dlq.queue
Type Input<string>
The name of the dead letter queue.
dlq.retry?
Type Input<number>
Default 3
The number of times the main queue will retry the message before sending it to the dead-letter queue.
dlq.retryDelay?
Type Input<“${number} second” | “${number} seconds”>
Default 0 seconds
The number of seconds to delay before making the message available for another attempt.
maxConcurrency?
Type Input<number>
Default null
Maximum number of concurrent consumers that may consume from this Queue.
transform?
transform.queue?
Type QueueArgs | (args: QueueArgs, opts: ComponentResourceOptions, name: string) => void
Transform the Queue resource.
Properties
id
Type Output<string>
The generated id of the queue
nodes
nodes.queue
Type Queue
The Cloudflare queue.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Bindings
Methods
getSSTLink
getSSTLink()Returns Object
subscribe
subscribe(subscriber, args?, opts?)Parameters
The worker that’ll process messages from the queue.subscriberInput<string|WorkerArgs>
Configure the subscription.args?QueueSubscribeArgs
Component resource options.opts?ComponentResourceOptions
Returns QueueWorkerSubscriber
Subscribe to the queue with a worker.
Subscribe to the queue with a worker file.
queue.subscribe("consumer.ts");Pass in full worker props.
const bucket = new sst.cloudflare.Bucket("MyBucket");
queue.subscribe({ handler: "consumer.ts", link: [bucket],});Configure batch settings.
queue.subscribe("consumer.ts", { batch: { size: 10, window: "20 seconds", },});QueueSubscribeArgs
batch?
batch.size?
Type Input<number>
Default 10
The maximum number of events that will be processed together in a single invocation of the consumer function.
Value must be between 1 and 100.
Set batch size to 1. This will process events individually.
{ batch: { size: 1 }}batch.window?
Type Input<“${number} minute” | “${number} minutes” | “${number} second” | “${number} seconds”>
Default “5 seconds”
The maximum amount of time to wait for collecting events before sending the batch to the consumer function, even if the batch size hasn’t been reached.
Value must be between 0 seconds and 60 seconds.
{ batch: { window: "5 seconds" }}transform?
transform.consumer?
Type QueueConsumerArgs | (args: QueueConsumerArgs, opts: ComponentResourceOptions, name: string) => void
Transform the Consumer resource.
transform.worker?
Type WorkerArgs | (args: WorkerArgs, opts: ComponentResourceOptions, name: string) => void
Transform the Worker resource.