AMQP / RabbitMQ - Avoiding Race Conditions

I have the following architecture: Architecture

  • There is a fixed number of input sources. Each input source is equivalent.
  • Broker AMQP. I am using RabbitMQ in my case.
  • There are currently 2 consumers. Again, each consumer is equivalent.

Input sources send commands for processing. These commands are forwarded by the broker and are picked up by one of two consumers.

I need the following behavior:

  • If a single input source sends multiple commands, all commands must be processed sequentially. That is, in the example of 2 commands, it is not allowed that consumer 1 processes command 1, while consumer 2 processes command 2 at the same time.
  • However, two commands coming from two different input sources can be processed simultaneously.

Is it possible to enforce this behavior using AMQP / RabbitMQ?

+4
source share
2 answers

You can cover your scenario using one user for each queue. Each queue can process the message sequentially.

Another way is to use only one queue and use envelope.getExchange()to understand the source, or tagyour messages, usingAMQP.BasicProperties properties

Thus, for example, you can consume messages in multithreading and assign one thread for each tag

0
source

, . , , .

0

All Articles