Aswin Moothedath
Aswin Moothedath

Reputation: 35

Get messages at consumer at exact order that was published - RabbitMQ - MassTransit

I am passing payment related data through queue. So I need to receive data at my consumer in same order that I have send.

Example - Publisher publish these message - msg1, msg2, msg3...msg8. At Consumer am not getting it in correct order that was published... it comes like msg1,msg4,msg2,msg7.msg8.. All the messages are of same type.. Is there any way to handle this in rabbitmq masstransit ?

Upvotes: 0

Views: 698

Answers (1)

Alexey Zimarev
Alexey Zimarev

Reputation: 19610

Purely pub-sub message brokers cannot guarantee ordering by design. Publisher acknowledgements and consumer acknowledgements aren't ordered, so messages can be published out of order (although you do it sequentially) and consumed out of order. When a message ends in the poison queue, the next message gets processed, so the order is broken by definition.

In addition, RMQ itself guarantees "at least one" delivery, which means that you can get the same message twice from the broker, out of order. Also, if RMQ cluster gets partitioned by network failure, the state of queues won't properly replicate, and the detached node will resend all the messages it has from its queues when the partitioned state is resolved.

Ordered delivery can only be supported with brokers that use append-only logs. You can do it with Kafka, for example. That's the reason that Kafka transport in MassTransit is implemented as a Rider, not as a normal message transport, due to the conceptual mismatch.

Upvotes: 1

Related Questions