HBForge/Examples
14 · Integrations

Cloudflare Queue — async work

Enqueue work over HTTP, consume in the same Worker via a queue() handler.

forge/serverCF Workers
Code
cloudflare-queue.js
import { WebApp } from class="tk-str">'@hyperbridge/forge/server';
const app = new WebApp();

app.post(class="tk-str">'/enqueue', async (c) => {
  await c.env.MY_QUEUE.send(await c.req.json());
  return c.json({ ok: true });
});

export default {
  fetch: app.fetch,
  async queue(batch, env) {
    for (const msg of batch.messages) {
      console.log(class="tk-str">'processing', msg.body);
      msg.ack();
    }
  },
};
How it works

Cloudflare's queue() handler runs whenever Workers picks up a batch. Acknowledge each message individually for granular retry control.

fetch: app.fetch wires the WebApp into the Worker's HTTP entry; queue sits alongside as a sibling handler.

For Node-side queues without Cloudflare, use forge/queue directly — same API, runs in-process.

Try it
Quickstart
wrangler dev → POST /enqueue → tail logs for processing
Related modules