Quickstart
This guide shows how to send your first queue message and process it with the @vercel/queue SDK.
In this quickstart:
- Your API route acts as a producer. It sends work to a queue topic.
- The topic (
orders) stores messages durably until a consumer processes them. - A second route acts as a consumer. Vercel invokes it automatically in push mode.
- A Vercel account
- Vercel CLI installed (
npm i -g vercel) - Node.js 22+
Install
@vercel/queueso your app can send messages and receive push callbacks.Terminalpnpm i @vercel/queueCreate a shared queue client and export helper methods:
lib/queue.tsimport { QueueClient } from '@vercel/queue'; const queue = new QueueClient({ region: process.env.QUEUE_REGION!, }); export const { send, handleCallback } = queue;This client is your app's connection to Vercel Queues in one region:
sendpublishes messages to a topic.handleCallbackhandles messages delivered to your consumer route.
Use a Vercel region close to your app and set it in
QUEUE_REGION.Create a route that publishes to a topic:
app/api/orders/route.tsimport { send } from '@/lib/queue'; export async function POST(request: Request) { const body = await request.json(); const { messageId } = await send('orders', { orderId: body.orderId, action: 'process', }); return Response.json({ messageId }); }When this route runs, it sends a message to the
orderstopic and returns amessageId.Think of this as "enqueue work now, process it right after."
Add a queue trigger in
vercel.json:vercel.json{ "functions": { "app/api/queues/process-order/route.ts": { "experimentalTriggers": [{ "type": "queue/v2beta", "topic": "orders" }] } } }This trigger maps the
orderstopic to your consumer route. Without this mapping, Vercel does not know where to deliver pushed messages.Then create the consumer route:
app/api/queues/process-order/route.tsimport { handleCallback } from '@/lib/queue'; export const POST = handleCallback(async (message, metadata) => { await processOrder(message); });The handler receives:
message: the payload you publishedmetadata: delivery details likemessageIdand retry count
If the handler succeeds, the message is acknowledged automatically. If it throws, the message is retried.
Deploy your app to Vercel, then call your publish route to enqueue a message. Vercel Queues invokes your consumer automatically in push mode.
You should see your consumer function run for each published message.
At this point, your flow is live:
- Your producer route receives a request
- It publishes a message to
orders - Vercel pushes that message to your consumer
- Your consumer processes and acknowledges it
- Installed the SDK: Added
@vercel/queueto your project. - Created a producer: Published messages to the
orderstopic. - Configured a consumer: Registered a push trigger and handler to process messages.
Was this helpful?