Message queue, if workers are not used,

Message queue, if workers are not used, can only use HTTP polling to check if messages exist?
8 Replies
Sid
Sid5mo ago
Not sure I understand. There currently isn't a way to poll for existence of messages, but you can pull messages and check if you get nothing back? https://developers.cloudflare.com/api/resources/queues/subresources/messages/methods/pull/
Cloudflare API | Queues › Messages › Pull Queue Messages
Interact with Cloudflare's products and services via the Cloudflare API
yinxingmaiming6409
yinxingmaiming6409OP5mo ago
What I mean is, how can I receive messages in real time? Do I have to make regular HTTP requests?
Sid
Sid5mo ago
Right. Unless you have a reason to use the HTTP pull endpoints, I’d highly recommend using a Worker with a queue() handler. That’ll run automatically when there are messages in your Queue, and also handle concurrency for you
Sid
Sid5mo ago
Cloudflare Docs
Getting started
Cloudflare Queues is a flexible messaging queue that allows you to queue messages for asynchronous processing. By following this guide, you will create your first queue, a Worker to publish messages to that queue, and a consumer Worker to consume messages from that queue.
yinxingmaiming6409
yinxingmaiming6409OP5mo ago
If I use a worker to process a queue and read it once, will it consume the number of times my worker reads it and the queue reads it once? So if I have 20 million reads, he will consume 40 million credits?
Sid
Sid5mo ago
If you’re doing 20 million reads, it means you also pushed 20 million messages, and assuming you also acknowledged each of them, you’d be paying for 60 million operations, which would be $23.60. There are a few pricing examples here that may be helpful: https://developers.cloudflare.com/queues/platform/pricing/#examples Using a Worker doesnt change this math, the advantage of using a Worker is that you don’t have to poll for messages, the platform will invoke your queue() handler automatically when there are messages. You would pay the same even if you used HTTP Pull.
yinxingmaiming6409
yinxingmaiming6409OP5mo ago
If I want to execute a Python AI recognition program after receiving a message, how should I implement it? Workers definitely can't run AI models, right? Identify images
Sid
Sid5mo ago
You might be interested in Workers AI: https://developers.cloudflare.com/workers-ai/ but if you do not want to use this, then you’ve got two options: switch back to HTTP Pull, using Queues from Python counts as having a reason to use HTTP Pull like I was saying earlier. Or if this program is exposed over an HTTP endpoint, you could call that from your queue() handler.
Cloudflare Docs
Cloudflare Workers AI
Workers AI allows you to run AI models in a serverless way, without having to worry about scaling, maintaining, or paying for unused infrastructure. You can invoke models running on GPUs on Cloudflare's network from your own code — from Workers, Pages, or anywhere via the Cloudflare API.

Did you find this page helpful?