Need help in setting up queue in workers
hey I am creating a simple worker to get html code of websites, I want to create a worker which gets urls from local json file, and send them in a queue this queue then invoke other worker which will do the rest, I read documentation but found that i have to do it in a single worker fucntion, I can undersatnd anything there, please help me how to do this?
1 Reply
Hi 👋
You'll need to add a queue producer and consumer binding to your
wrangler.toml
(with a queue already created):
You can add these two into different workers, you could even have multiple producers - just one consumer.
You can then push a new message with env.MY_QUEUE.send({'your data': 'goes here'})
Which will call the queue
handler of your worker. Here's a small example:
Batches of messages will be delivered to the queue() handler here, and you can acknowledge/retry them one by one or all at once.
Here's a tutorial for a small crawler that's hopefully going to help you: https://developers.cloudflare.com/queues/tutorials/web-crawler-with-browser-rendering/#1-build-the-crawler-workerCloudflare Docs
Cloudflare Queues - Queues & Browser Rendering · Cloudflare Queues
This tutorial explains how to build and deploy a web crawler with Queues, Browser Rendering, and Puppeteer.