Skip to content

Queues and background events

ermahgerd provides organization-scoped durable queues with the familiar Cloudflare Workers producer and consumer interfaces. Queues are managed through Wrangler and the console; Worker code sends with env.QUEUE.send() and consumes with an exported queue(batch, env, ctx) handler.

Create queues

Configure your connection as described in Connect Wrangler, then create the primary and dead-letter queues:

npx wrangler queues create documents
npx wrangler queues create documents-dlq

Queue names are scoped to the authenticated organization. Two organizations may both own a queue named documents; their registries, broker state, messages, consumers, and DLQs remain distinct.

Queues do not have a public hostname. Their data plane is deliberately exposed through scoped Worker bindings, while their management plane uses the authenticated /accounts/<organization>/queues API.

Produce messages

Declare a producer binding in Wrangler configuration:

{
  "queues": {
    "producers": [{ "binding": "DOCUMENTS", "queue": "documents" }]
  }
}

Then send from request or scheduled code:

await env.DOCUMENTS.send({ id, document });

The trusted runtime adapter captures the calling organization and queue name. Worker code cannot replace that scope or obtain the queue service credential.

Consume messages

Attach a Worker consumer through the same Wrangler project:

{
  "queues": {
    "consumers": [
      {
        "queue": "documents",
        "max_batch_size": 10,
        "max_batch_timeout": 2,
        "max_concurrency": 4,
        "max_retries": 3,
        "retry_delay": 1,
        "dead_letter_queue": "documents-dlq"
      }
    ]
  }
}

The Worker exports the native queue handler:

export default {
  async queue(batch) {
    for (const message of batch.messages) {
      console.log("Processing document", message.body);
      message.ack();
    }
  },
};

Wrangler creates or updates the consumer after uploading the Worker. Each delivery resolves the Worker’s current active version, so messages already waiting or retrying can be handled by a newly deployed revision without rewriting queue state. max_concurrency bounds the number of independent consumer invocations dispatched at once. Each invocation receives at most max_batch_size messages. Use a batch size of one when every message needs an independent execution budget, retry result, and trace.

Delivery, retries, and durability

The dedicated ermahgerd-queue.service hosts the registry, broker, and telemetry Durable Objects as one storage cohort. Messages are committed to Durable Object SQLite before send() resolves. The cohort uses the appliance’s platform-owned cluster storage with stable namespace identities; alarms recover delivery after process restarts. Delivery is at least once: consumers must make side effects idempotent.

Native ack(), retry(), ackAll(), and retryAll() results control settlement. An unsuccessful handler retries the batch. When retry attempts are exhausted, the broker moves the message to the configured queue in the same organization or drops it when no DLQ is configured. The current clustered profile has one queue member. It preserves state through service restarts and deterministic replacement, but does not replicate queue state or automatically fail over to another host.

Open Queues in the console to inspect backlog and message activity. Use Observability to investigate queue invocations, errors, and logs.

Organization queue inventory and delivery-state summary

A DLQ is an ordinary queue and can be inspected there. Deletion is rejected while a queue contains messages; purging is a separate confirmed operation. Deleting an empty queue also removes its historical broker state, so recreating the name starts clean.

For a consumer Worker’s invocation outcomes and logs, see Worker observability. Operator delivery objectives are described in Platform observability.

Compose a background workflow

The queue-to-storage example accepts a JSON document over HTTP, enqueues it, and writes it to an R2 bucket from a background consumer. The order pipeline adds database updates, and the photo workflow combines queued image processing and optional AI metadata.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close