Emad Mamaghani
Emad Mamaghani

Reputation: 377

RabbitMQ: Does ignoring prefetch() causes data concurrency?

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?

Upvotes: 1

Views: 426

Answers (1)

spike 王建
spike 王建

Reputation: 1714

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.

Upvotes: 2

Related Questions