Do RPCs work in localhost? 🤔

Haven't been able to make them work and getting a The RPC receiver does not implement the method "sendTestEmail" error even though I have the 2 workers services running.
1 Reply
fforres
fforres3mo ago
I can see the following: ▲ [WARNING] This worker is bound to live services: TRANSACTIONAL_EMAIL_SERVICE (transactional-email-service) Which makes me think wrangler does see the bound RPC service. Plus I have set a compatibility_date = "2024-06-03" for both my services (main and the bound RPC). Holy shit! I figured it out my issue. So one extra thing to have in consideration is that methods have to be written as part of the class prototype. Like WORKS
export default class DB extends WorkerEntrypoint {
async method() {
// Prototype method implementation
console.log("Prototype method called and everyone is happy");
}
}
export default class DB extends WorkerEntrypoint {
async method() {
// Prototype method implementation
console.log("Prototype method called and everyone is happy");
}
}
FAILS
export default class DB extends WorkerEntrypoint {
someMethod = async () => {
// Arrow function method implementation
console.log("Arrow function method called");
// This will not be called. The host worker will fail with a message like:
// The RPC receiver does not implement the method someMethod
}
}
export default class DB extends WorkerEntrypoint {
someMethod = async () => {
// Arrow function method implementation
console.log("Arrow function method called");
// This will not be called. The host worker will fail with a message like:
// The RPC receiver does not implement the method someMethod
}
}
Unsure if this is documented or not, but that was at least my issue 🙏 I imagine this has to be because the way workers need keep references to JS Objects when injecting RPCs? 🤔 Would be great if some CF folks could give some insight
Want results from more Discord servers?
Add your server