nitro-queue
v0.0.7
Published
Queue module for Nitro
Readme
Outline
A module for Nitro v3 that provides Cloudflare Queue support.
pnpm add nitro-queueFeatures
- Automatically configures queue routes by scanning the
queuesdirectory - Overwrite queue types in your env using the
npx nitro-queue types cloudflare.d.tscommand - The module handles routing queues from
cloudflare:queueautomatically
Prerequisites
Initialize the module
// nitro.config.ts
import queue from 'nitro-queue'
import { defineNitroConfig } from 'nitro/config'
export default defineNitroConfig({
modules: [queue()],
})cloudflare.d.ts
Cloudflare can generate types through the wrangler config file. nitro-queue then modifies the types generated by wrangler to match your project's queue types.
{
"scripts": {
"prepare": "pnpm types:cloudflare && pnpm types:queue",
"types:cloudflare": "wrangler types cloudflare.d.ts --config ./.output/server/wrangler.json",
"types:queue": "npx nitro-queue types cloudflare.d.ts"
}
}How to use
// queues/user/remove.ts
export default defineQueue<{
userId: string
}>({
run(payload) {
console.log(payload.userId)
}
})
// routes/publish.ts
export default defineHandler(async (e) => {
e.runtime.cloudflare.env.MY_QUEUE.send({
type: 'user:remove',
payload: { userId }
})
})Note
This module has not been thoroughly tested. If you encounter any bugs, please feel free to open an issue. Your feedback is greatly appreciated.
