Using local DO bindings from another worker script
I am trying to use DO bindings for local development but I am running into some issues. The docs (https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development) seem to indicate that you can bind two local workers by calling
wrangler dev
on each of them. But that is giving me an issue.
My DO worker is defined like this:
here is the wrangler.json:
Then I am trying to call the DO from another worker like so:
the wrangler.json is defined as:
I try to run wrangler dev on the DO worker and then wrangler dev on the main worker, however the main worker gives me this message:
Then when I try to access the DO, it is giving: DO access error: Error: Cannot access 'DurableObjectClassName#sayHello' as Durable Object RPC is not yet supported between multiple 'wrangler dev' sessions.
The docs seem to indicate that it is supported. If I run wrangler dev -c wrangler.json -c do-worker/wrangler.json
, the two workers are able to communicate and the binding works correctly. Once I start them separately, then I am running into the issue that they can't talk.Cloudflare Docs
Service bindings - Runtime APIs · Cloudflare Workers docs
Facilitate Worker-to-Worker communication.
1 Reply
Ok I was able to do a little digging and figured out the following:
Once I added a durable_object binding to the DO worker, it is saying that they are connected when I run wrangler dev.
The DO wrangler.json looks like this:
then the output of wrangler dev from the other worker is:
So now it says they are connected, but it is still giving the same error
Error: Cannot access 'DurableObjectClassName#sayHello' as Durable Object RPC is not yet supported between multiple 'wrangler dev' sessions
.
When I use wrangler dev -c wrangler.json -c do-worker/wrangler.json
, they are binding correctly and the output of wrangler dev is
I guess the error makes sense that it can't use RPC between two wrangler dev sessions, but when it is run as a combined wrangler dev section, then the RPC starts to work. Maybe I will just have to use fetch to access the DO during development? It would be really nice to figure out how to use the RPC though, I don't want to have two sets of logic between local and remote.