Multiple Producers on same Queue
I’m not an expert on miniflare but I’ll look into how to make sure multiple local workers are bound to the same Queue.
15 Replies
Following up on this. I played around with the mounting functionality described here: https://miniflare.dev/core/mount but wasn't able to get something to work. I'm following up with the author of Miniflare (he works at Cloudflare now) and maybe he'll have some ideas.
If multiple workers writing to the same queue in local dev mode is a requested feature we can definitely prioritize that as part of our push towards GA.
🔌 Multiple Workers · Miniflare
Fun, full-featured, fully-local simulator for Cloudflare Workers
@charlieburnett for visibility 🙂
I'm with the OP on this one - just want to be able to test both my producer and my consumer, and don't need multiple producers.
To be clear, that's totally doable right now. You have to be using module Worker syntax (https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/) and define both the
fetch
and queue
entrypoints on the same script.Migrating to module Workers · Cloudflare Workers docs
This guide will show you how to migrate your Workers from the Service Worker syntax to the new Module Worker format.
I see - so that would enable local dev testing for both producer and consumer? In production I was assuming these would need to be separate workers, but perhaps it doesn't actually matter
It's not as versatile as having two separate
wrangler dev --local
instances automagically bind to the same queue, but it does give you the ability to emulate a full queue workflow locally.
You're free to do as you please, and it can totally be the same worker. Personally I do have an instance of the same Worker script being used as a producer and consumer. You can think of it as whether you want separate Docker images for an application that talks to SQS or not.Yep - that works like a champ! Thanks @oilylime!
https://discord.com/channels/595317990191398933/891052295410835476/1094412946328789003
This may work as well, I can’t try until tomorrow
Following up here, got some help from our resident Miniflare author, and just tested it personally, here's something that works! Multiple producers, single consumer.
index.js
:
In the above example you'd want to swap out
script
from the mounts to the source of your worker scripts. Here's the miniflare API for reference: https://miniflare.dev/get-started/api🧰 Using the API · Miniflare
Fun, full-featured, fully-local simulator for Cloudflare Workers
Gotcha. So the goal is a file that uses miniflare directly and can run all of my monorepo at once
Thanks for going so deep on this guys
Yeah, by invoking the Miniflare API in js directly you have a good amount of control. It was a learning experience for me too, and a valuable one.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yeah, you need to run it through esbuild first. The example someone sent me used esbuild directly, although there may be a way to do it with miniflare directly
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View