How will you use Cloudflare’s Queue/Consumer with Nitro/Nuxt? #3287
-
|
There’s mention of using runtime hooks in order to extend worker handlers, but I’ve not yet found a suitable example usage/tutorial on how to do so. In my code, I’m able to register queues, and send events. // wrangler.jsonc
"queues": {
"producers": [
{
"queue": "le-queue",
"binding": "QUEUE"
}
],
"consumers": [
{
"queue": "le-queue",
"max_batch_size": 100,
"max_batch_timeout": 5,
"max_retries": 3,
"dead_letter_queue": "le-dead-letter-queue",
}
]
},// env.d.ts
import type { Queue } from "@cloudflare/workers-types/experimental";
declare module "h3" {
interface H3EventContext {
context: ExecutionContext;
cloudflare: {
request: Request;
env: {
QUEUE: Queue
};
};
}
}Somewhere in my code I do: const message = {
name: “Pooya”
};
event.context.cloudflare.env.QUEUE.send(message)
Thanks, and apologies for pinging 🙈 |
Beta Was this translation helpful? Give feedback.
Answered by
they-cloned-me
Apr 6, 2025
Replies: 1 comment
-
|
Maybe listen for this in a plugin? // server/plugins/000.queue.ts
import { MessageBatch } from "@cloudflare/workers-types/experimental";
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("cloudflare:queue", async (params: {
batch: MessageBatch;
}) => {
// 🤔 🫤
console.log(params.batch.messages)
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
they-cloned-me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe listen for this in a plugin?