Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/2.deploy/20.providers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,72 @@ Alternatively, Nitro also detects Bun automatically if you specify a `bunVersion
}
```

## Queues

:read-more{title="Vercel Queues" to="https://vercel.com/docs/queues"}

Nitro integrates with [Vercel Queues](https://vercel.com/docs/queues) to process messages asynchronously. Define your queue topics in the Nitro config and handle incoming messages with the `vercel:queue` runtime hook.

```ts [nitro.config.ts]
export default defineNitroConfig({
vercel: {
queues: {
triggers: [
// Only `topic` is required
{ topic: "notifications" },
{ topic: "orders", retryAfterSeconds: 60, initialDelaySeconds: 5 },
],
},
},
});
```

::note
The [`@vercel/queue`](https://www.npmjs.com/package/@vercel/queue) package is required when using queues. Install it in your project with your package manager.
::

### Handling messages

Use the `vercel:queue` hook in a [Nitro plugin](/guide/plugins) to process incoming queue messages:

```ts [server/plugins/queues.ts]
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("vercel:queue", ({ message, metadata, send }) => {
console.log(`[${metadata.topicName}] Message ${metadata.messageId}:`, message);
});
});
```

### Running tasks from queue messages

You can use queue messages to trigger [Nitro tasks](/guide/tasks):

```ts [server/plugins/queues.ts]
import { runTask } from "nitropack/runtime";

export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("vercel:queue", async ({ message, metadata }) => {
if (metadata.topicName === "orders") {
await runTask("orders:fulfill", { payload: message });
}
});
});
```

### Sending messages

Use the `@vercel/queue` package directly to send messages to a topic:

```ts [server/routes/api/orders.post.ts]
import { send } from "@vercel/queue";

export default defineEventHandler(async (event) => {
const order = await readBody(event);
const { messageId } = await send("orders", order);
return { messageId };
});
```

## Custom build output configuration

You can provide additional [build output configuration](https://vercel.com/docs/build-output-api/v3) using `vercel.config` key inside `nitro.config`. It will be merged with built-in auto-generated config.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"@types/semver": "^7.7.1",
"@types/serve-static": "^2.2.0",
"@types/xml2js": "^0.4.14",
"@vercel/queue": "^0.1.4",
"@vitest/coverage-v8": "^4.1.2",
"automd": "^0.4.3",
"changelogen": "^0.6.2",
Expand All @@ -207,9 +208,13 @@
"xml2js": "^0.6.2"
},
"peerDependencies": {
"@vercel/queue": "^0.1.4",
"xml2js": "^0.6.2"
},
"peerDependenciesMeta": {
"@vercel/queue": {
"optional": true
},
"xml2js": {
"optional": true
}
Expand Down
Loading