Queues
Use queues to process work asynchronously, such as sending emails or handling uploads. Define a consumer in queues/, then send it typed messages from your app.
Defining queues
Create a consumer in queues/. TypeScript and JavaScript files are supported (.ts, .mts, .js, .mjs). Its path determines the queue name: queues/emails.ts creates emails, and queues/order/notifications.ts creates order-notifications. Each queue must have a unique name.
The resulting name must follow Cloudflare's queue naming rules: 1–63 characters, only letters, digits, and -, beginning and ending with a letter or digit. On void deploy --platform cloudflare, the Cloudflare queue also carries the Worker name, so the limit applies to that full name; see Cloudflare queue names.
Export a default handler wrapped with defineQueue<T>. T defines the message body for both the consumer and calls to send():
// queues/emails.ts
import { defineQueue } from 'void';
interface Message {
to: string;
subject: string;
}
export default defineQueue<Message>(async (batch, env) => {
for (const msg of batch.messages) {
console.log(`Send to ${msg.body.to}: ${msg.body.subject}`);
msg.ack();
}
});Files or directories starting with _ are ignored.
Sending messages
Send messages through the property matching the queue name. TypeScript checks each message against the consumer’s defineQueue<T> type.
// routes/api/orders.ts
import { defineHandler } from 'void';
import { queues } from 'void/queues';
export const POST = defineHandler(async (c) => {
const order = await c.req.json();
await queues.emails.send({
to: order.email,
subject: 'Order confirmed',
});
return c.json({ ok: true });
});Per-message acknowledgment
Each message in the batch has ack() and retry() methods matching the Cloudflare Queues API:
export default defineQueue<Message>(async (batch, env) => {
for (const msg of batch.messages) {
try {
await processMessage(msg.body);
msg.ack();
} catch {
msg.retry({ delaySeconds: 30 });
}
}
});msg.ack(): acknowledge the message and remove it from the queuemsg.retry(options?): retry the message, optionally with a{ delaySeconds }delaybatch.ackAll(): acknowledge all messages in the batchbatch.retryAll(options?): retry all messages in the batch
The first ack() or retry() call wins for each message. Messages without an explicit decision are acknowledged when the handler succeeds and retried when it throws. Void logs handler errors automatically.
The timestamp field on each message is a Date object.
Consumer options
Export named constants to configure how Cloudflare delivers batches to your consumer:
// queues/emails.ts
import { defineQueue } from 'void';
interface Message {
to: string;
subject: string;
}
export const maxBatchSize = 50;
export const maxBatchTimeout = 10; // seconds
export const maxConcurrency = 2;
export const maxRetries = 5;
export const retryDelay = 30; // seconds
export default defineQueue<Message>(async (batch, env) => {
for (const msg of batch.messages) {
console.log(`Send to ${msg.body.to}: ${msg.body.subject}`);
}
});maxBatchSize: maximum number of messages per batch (default10)maxBatchTimeout: maximum seconds to wait before delivering an incomplete batch (default5)maxConcurrency: maximum number of batches processed concurrently, from1to250(default: Cloudflare automatic scaling)maxRetries: maximum number of retries before delivery is exhausted (default3)retryDelay: seconds to wait between retries (default0)
Export each option directly from the queue file as a whole number, such as export const maxRetries = 5. Computed values and re-exports aren't supported; repeat shared settings in each queue file.
If the email provider in this example can handle two batches at a time, export maxConcurrency = 2. Cloudflare can still deliver up to maxBatchSize messages in each batch. See consumer concurrency.
Void-managed deployments require platform version 1.10.0 or later.
Void-managed queues do not configure a dead-letter queue. Cloudflare permanently deletes messages that exhaust their retries without one; see Cloudflare's dead-letter queue guide.
Void provisions queues and connects their producers and consumers when you deploy.
Cloudflare queue names
With void deploy --platform cloudflare, queue names include the Worker name: queues/jobs.ts in app-staging creates app-staging-jobs. Underscores in the Worker name become hyphens. Your app uses queues.jobs.send() in every environment.
Keep the full name within 63 characters and unique within the account. Each Cloudflare queue supports one consumer; Void reports naming or consumer conflicts during deploy.
Existing deployments keep their queues and messages. To adopt the new naming, pause producers, drain the old queue, remove its Worker consumer in Cloudflare, and redeploy. Check that the old queue is empty before deleting it.
Local development
In a native Void app, sending a message to queues.emails on the dev server runs your email consumer. To try a specific batch, send it to the local queue endpoint.
POST /__void/queue
Content-Type: application/json
{ "queue": "<queue-name>", "messages": [{ "id": "1", "timestamp": <unix_ms>, "body": <any>, "attempts": 1 }] }Start the dev server and copy the curl command it prints. The command includes the local port and trigger token. This example sends an order confirmation to the emails consumer.
curl -X POST http://localhost:5173/__void/queue \
-H "Content-Type: application/json" \
-H "x-void-dev-trigger: <printed-token>" \
-d '{"queue":"emails","messages":[{"id":"1","timestamp":'"$(date +%s000)"',"body":{"to":"alice@example.com","subject":"Order confirmed"},"attempts":1}]}'In a supported meta-framework, use the dev endpoint to run the consumer with your framework’s bindings. A local send alone won’t run it. The manual trigger is available in the dev server only.