nitro-vc-queues

https://nitro-vc-queues.vercel.app/

3
0
3
HTML
public

Nitro + Vercel Queues

A minimal Nitro example showing how to send messages to Vercel Queues from a Hono server entry, and process them via the vercel:queue hook registered from a Nitro plugin.

What’s in here

  • nitro.config.ts — declares two queue triggers (orders, notifications) under vercel.queues.triggers, and registers queue-handler.ts as a Nitro plugin.
  • server.ts — the server entry, a Hono app exposing POST /api/enqueue. It accepts { topic, message } and calls send(topic, message) from @vercel/queue.
  • queue-handler.ts — a Nitro plugin that hooks vercel:queue and dispatches incoming messages to a per-topic handler via metadata.topicName.

Run locally

pnpm install
pnpm dev

Note: vercel:queue only fires when deployed to Vercel. Locally you can still hit POST /api/enqueue, but send() requires Vercel credentials and the consumer function won’t run.

Deploy

pnpm build
npx vercel deploy --prebuilt

How the hook dispatch works

queue-handler.ts is a Nitro plugin that registers a single vercel:queue hook and looks up a handler by metadata.topicName:

export default definePlugin((nitro) => {
  nitro.hooks.hook("vercel:queue", async ({ message, metadata }) => {
    const handler = handlers[metadata.topicName];
    await handler?.(message, metadata);
  });
});

Add a new topic by adding an entry to vercel.queues.triggers in nitro.config.ts and a matching key in the handlers map.

v0.3.3[beta]