Skip to content
25K
Console

Queue

The Queue component lets you add a Cloudflare Queue to your app.

Create a Queue

sst.config.ts
const queue = new sst.cloudflare.Queue("MyQueue");

Subscribe to the Queue

Create a worker file that exposes a default handler for queue messages:

consumer.ts
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.

sst.config.ts
queue.subscribe("consumer.ts");

You can link other workers to the queue.

sst.config.ts
new sst.cloudflare.Worker("MyWorker", {
handler: "producer.ts",
link: [queue],
url: true,
});

Subscribe with full worker props

sst.config.ts
const bucket = new sst.cloudflare.Bucket("MyBucket");
queue.subscribe({
handler: "consumer.ts",
link: [bucket],
});

Constructor

new Queue(name, args?, opts?)

Parameters

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?

Type Object

Transform how this component creates its underlying resources.

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

Type Object

The underlying resources this component creates.

nodes.queue

Type Queue

The Cloudflare queue.

SDK

Use the SDK in your runtime to interact with your infrastructure.


Bindings

Methods

getSSTLink()

Returns Object

subscribe

subscribe(subscriber, args?, opts?)

Parameters

Returns QueueWorkerSubscriber

Subscribe to the queue with a worker.

Subscribe to the queue with a worker file.

sst.config.ts
queue.subscribe("consumer.ts");

Pass in full worker props.

sst.config.ts
const bucket = new sst.cloudflare.Bucket("MyBucket");
queue.subscribe({
handler: "consumer.ts",
link: [bucket],
});

Configure batch settings.

sst.config.ts
queue.subscribe("consumer.ts", {
batch: {
size: 10,
window: "20 seconds",
},
});

QueueSubscribeArgs

batch?

Type Object

Default 10

The maximum number of messages to include in a 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?

Type Object

Transform how this component creates its underlying resources.

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.