Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple consumers & producers connected to a message queue, Is that possible in AMQP?

I'd like to create a farm of processes that are able to OCR text. I've thought about using a single queue of messages which is read by multiple OCR processes.

I would like to ensure that:

  • each message in queue is eventually processed
  • the work is more or less equally distributed
  • an image will be parsed only by one OCR process
  • An OCR process won't get multiple messages at once (so that any other free OCR process can handle the message).

Is that possible to do using AMQP?

I'm planning to use python and rabbitmq

like image 451
Piotr Czapla Avatar asked Jan 29 '10 10:01

Piotr Czapla


People also ask

Can a topic have multiple consumers?

A topic can be consumed by many consumer groups and each consumer group will have many consumers. A topic is divided into multiple partitions. A consumer in a consumer group is assigned to a partition. Only one consumer is assigned to a partition.

Can a queue have multiple consumers?

Support for multiple-consumer queues is a Message Queue feature (the JMS specification defines messaging behavior in the case of only one consumer accessing a queue). When multiple consumers access a queue, the load-balancing among them takes into account each consumer's capacity and message processing rate.

How do you use multiple consumers in Kafka?

To run multiple consumers in the same group in one application, you will need to run each in its own thread. It is useful to wrap the consumer logic in its own object and then use Java's ExecutorService to start multiple threads each with its own consumer.

Can RabbitMQ have multiple consumers?

In RabbitMQ, we can have multiple consumers listening from one queue. This is good for fast procesing, but not so good for message ordering.


1 Answers

Yes, as @nailxx points out. The AMQP programming model is slightly different from JMS in that you only have queues, which can be shared between workers, or used privately by a single worker. You can also easily set up RabbitMQ to do PubSub use cases or what in JMS are called topics. Please go to our Getting Started page on the RabbitMQ web site to find a ton of helpful info about this.

Now, for your use case in particular, there are already plenty of tools available. One that people are using a lot, and that is well supported, is Celery. Here is a blog post about it, that I think will help you get started:

If you have any questions please email us or post to the rabbitmq-discuss mailing list.

like image 97
alexis Avatar answered Sep 29 '22 22:09

alexis