Search code examples
publish-subscribeservicebusmasstransit

Masstransit message consumption order


I have a publishing endpoint 'P' and two consumers 'A', 'B'.
When 'P' publish messages '1' '2' '3', I expect that consumers would consume messages with the order of '123'. But in reality consumption order maybe '132', '312' and so forth.
I have configured the settings related to concurrency but it doesn't work
concurrency settings


Question: Is there a configuration that could prevent 'B' from taking message until 'A' consumes message successfully ?

Thanks


Solution

  • There is no guarantee regarding processing messages in order, and should be avoided at all costs.

    Messages in the queue is FIFO but when you have multiple consumers with pre-fetch setup, each consumer A and B will pull x messages off the queue, and process them depending on how long it takes it, consumer A could go back for more message before consumer B is done, and process messages out of order which is common situation.

    Message retries could also cause messages to be processed out of order.

    Saying this, if you do required this, using a single consumer set with a concurrency limit of 1 would process messages in order, at the cost of throughput.