---
title: "Queues"
---

> Documentation Index
> Fetch the complete documentation index at: https://workerd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Queues

[Queues](https://developers.cloudflare.com/queues/) is a message broker. A
producer sends a message, and a consumer receives it later in a batch.
workerd keeps the messages in SQLite-backed Durable Objects under
`.wrangler/state/workerd/queues/`. Read the
[Cloudflare Queues documentation](https://developers.cloudflare.com/queues/configuration/javascript-apis/)
for the API.

## Example

The Queues example sends a job for each request
and processes it in a queue handler. A job for a path that ends in `/fail`
retries twice, and then the example reads it from a dead-letter queue.

```js title="index.js"
export default {
  async fetch(request, env) {
    const job = {
      path: new URL(request.url).pathname,
      createdAt: new Date().toISOString(),
    };
    await env.JOBS.send(job);
    return Response.json({ queued: job });
  },

  async queue(batch) {
    for (const message of batch.messages) {
      if (batch.queue === "example-jobs-dead-letter") {
        console.log("dead job", message.body);
        message.ack();
        continue;
      }

      if (message.body.path.endsWith("/fail")) {
        console.log("retrying job", message.body, message.attempts);
        message.retry({ delaySeconds: 1 });
        continue;
      }

      console.log("processing job", message.body);
      message.ack();
    }
  },
};
```

```jsonc title="wrangler.jsonc"
{
  "name": "queues",
  "main": "index.js",
  "compatibility_date": "2026-01-01",
  "no_bundle": true,
  "queues": {
    "producers": [{ "binding": "JOBS", "queue": "example-jobs" }],
    "consumers": [
      {
        "queue": "example-jobs",
        "max_batch_size": 10,
        "max_batch_timeout": 5,
        "max_retries": 2,
        "dead_letter_queue": "example-jobs-dead-letter"
      },
      { "queue": "example-jobs-dead-letter" }
    ]
  }
}
```

Queues is experimental, so it needs `--experimental`:

```sh
npx workerd serve --experimental ./queues/wrangler.jsonc
curl http://localhost:8787/hello
curl http://localhost:8787/job/fail
```

workerd logs `processing job` for `/hello`. For `/job/fail`, it logs
`retrying job` three times and then `dead job`, in about 15 seconds.

## Differences from Cloudflare

- The consumer of a queue is the Worker of the same `wrangler.jsonc` as the
  producer. A Worker in another configuration cannot reach the queue.
- A producer entry takes `binding`, `queue`, and `remote`. workerd ignores
  `remote` and refuses `delivery_delay`.
- workerd clamps a consumer setting that is out of range, and does not
  refuse it: `max_batch_size` to 1 through 100, `max_batch_timeout` to 60
  seconds, and `max_concurrency` to 1024.
- workerd keeps a message for four days, and the period is fixed.
- workerd has no pull consumers, no Queues HTTP API, and no event
  notifications or subscriptions.
- Queues does not work in a cluster yet. If a configuration with `queues`
  joins a cluster with `--cluster-addr`, workerd does not start.

See also [Cloudflare compatibility](https://workerd.dev/docs/cloudflare-compat/#services).

Source: https://workerd.dev/docs/services/queues/index.mdx
