Hey folks Heavy Cloudflare Workers user

Hey folks! Heavy Cloudflare Workers user here, and new Queues user - great to meet you all 👋 I'm struggling to bind a queue to a worker - specifically I can't get the binding to show up in the env argument in the fetch default exported function.
10 Replies
Jeremy Evans
Jeremy Evans2y ago
Here's my wrangler.toml file:
name = "savvy-queues"
main = "src/index.ts"
compatibility_date = "2023-01-23"

[vars]
TEST_VAR = "TEST_VALUE"

[[queues.producers]]
queue = "analytics-events-queue"
binding = "ANALYTICS_EVENTS_QUEUE"

[[queues.consumers]]
queue = "analytics-events-queue"
max_batch_size = 10
max_batch_timeout = 5
name = "savvy-queues"
main = "src/index.ts"
compatibility_date = "2023-01-23"

[vars]
TEST_VAR = "TEST_VALUE"

[[queues.producers]]
queue = "analytics-events-queue"
binding = "ANALYTICS_EVENTS_QUEUE"

[[queues.consumers]]
queue = "analytics-events-queue"
max_batch_size = 10
max_batch_timeout = 5
Unsmart
Unsmart2y ago
what wrangler version are you on? @jeremynevans
Jeremy Evans
Jeremy Evans2y ago
⛅️ wrangler 2.8.1 Here's my worker:
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
console.log("env", env);

let log;
log = await request.json();
await env.ANALYTICS_EVENTS_QUEUE.send(log);
return new Response("Success!");
},

async queue(batch: MessageBatch<Error>, env: Env): Promise<void> {
let messages = JSON.stringify(batch.messages);
console.log(`Consumed from our queue: ${messages}`);
},
};
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
console.log("env", env);

let log;
log = await request.json();
await env.ANALYTICS_EVENTS_QUEUE.send(log);
return new Response("Success!");
},

async queue(batch: MessageBatch<Error>, env: Env): Promise<void> {
let messages = JSON.stringify(batch.messages);
console.log(`Consumed from our queue: ${messages}`);
},
};
The console log prints out {TEST_VAR: "TEST_VALUE"} so the regular env variable is there but not the queue
Unsmart
Unsmart2y ago
did you create the queue on the dashboard?
Jeremy Evans
Jeremy Evans2y ago
I created it in wrangler (but have tried modifying it using the dashboard too)
Jeremy Evans
Jeremy Evans2y ago
Both bindings show up on the dashboard
No description
No description
Unsmart
Unsmart2y ago
Whenever you send a message to the queue does it work? Maybe it just doesnt show in the console.log 🤷
Jeremy Evans
Jeremy Evans2y ago
Sadly not, I get:
TypeError: Cannot read properties of undefined (reading 'send')
at Object.fetch
TypeError: Cannot read properties of undefined (reading 'send')
at Object.fetch
Unsmart
Unsmart2y ago
hmm im not really sure it looks correct
Jeremy Evans
Jeremy Evans2y ago
Oh interesting - when I try it outside the dashboard sandbox environment it works! So it's just inside the Quick Edit sandbox that it doesn't have the binding. Thanks anyway for your help!
Want results from more Discord servers?
Add your server