I have different worker environments inside wonrgler.toml
but I have two main problems
1- when publishing worker with wrangler cli it does not bind the queue with the worker, here is sanitized
wrangler.toml
file
type = "webpack"
account_id = "account_id"
workers_dev = false
webpack_config = "webpack.config.js"
compatibility_date = "2022-09-09"
zone_id = "87b8765c96412496773c3d9b19e064ea"
[env.staging]
name = "staging-env"
route = "staging-route"
r2_buckets = [
{ binding = "Bucket", bucket_name = "the-buket-name" }
]
[[queues.producers]]
queue = "the-queue-name"
binding = "Queue"
[[queues.consumers]]
queue = "the-queue-name"
max_batch_size = 100
max_batch_timeout = 30
[env.staging.vars]
# somv vars
[miniflare]
# miniflare
2- when i set queue binding from the dashboard it works but it does not set the queue consumer
here is the index.js file
addEventListener('fetch', async (event) => {
const request = event.request;
if (request.method === 'OPTIONS') {
event.respondWith(handleOptions(request));
} else {
event.respondWith(router.handle(event.request, event));
}
});
addEventListener('queue', async (event) => {
for (const message of event.batch.messages) {
const messageBody = JSON.parse(message.body);
switch (messageBody.status) {
// some cases
default:
break;
}
}
});