1

The scenario:

I have a single producer and consumer with only one queue which transfers messages. The consumer will update a value on DB according to the message that has consumed it. No operations should be sent to the DB in parallel. So, we shouldn't do anything that causes the data concurrency on DB. I use prefetch(1) to receive one message at a time. Does removing the prefetch() cause multiple operations to be sent to the DB in parallel or not?

Does consumer process messages in a single-threaded processor without prefetch() or not?

Emad Mamaghani
  • 343
  • 2
  • 14
  • This question can't be answered without more details about how you've written your consumer: RabbitMQ just delivers messages when asked for them, it can't control what happens next. For instance, if it was a PHP script, the answer would be trivial, because PHP has no native threading; in other languages, it will depend on what library you're using, and how you use it. – IMSoP Oct 24 '20 at 15:15

1 Answers1

2

Does prefetch lead to parallel

If we do not consider the case of single-threaded batch operations, we first need to know what leads to parallel? Multiple threads consuming.

The prefetch value defines the max number of unacknowledged deliveries that are permitted on a channel or consumer.

So prefetch only affects how many unconfirmed messages are stored in consumer memory. This does not involve consuming.

What configuration will lead to parallel

If we have a single channel, it has a single dispatch thread and hence all incoming messages are processed serially. An obvious way to achieve consumption parallelism is to increase the number of listening channels and consumers.

Although rabbitmq has many versions of clients, they are all written according to the AMPQ protocol, so there is not much difference.

spike 王建
  • 1,556
  • 5
  • 14