Axon AMQP - Single Queue Multiple Consumers


I am very new CQRS and Even sourcing and stumbled upon this neat library. I tried out the demo-complaints application it works quite well.

My question is if I have a queue where I push my Create Event and Update Event and if there are multiple consumers to this queue then there will be a case where update event could get picked up before a create event or lets say both went at exact time, we will end in an erroneous state. How can I sequence the events? Does Axon provide some mechanism to this? Is there any example anyone can point me to?


Any Inputs here?

Hi Sunand,

AMQP and multiple consumers is your issue here. With those multiple consumers, you lose the ability to guarantee ordering (unless you manage to implement that in the AMQP broker). If ordering is important, use a single consumer per queue.

If you need to sequence based on aggregate, you could use the sequence number in the DomainEventMessage to reorder messages. You’d have to keep track of sequence numbers and set them aside once you detect they don’t match the expected next number.

You probably want to use a single consumer on the queue, and then use an AsynchronousEventProcessingStrategy to execute your handlers in different threads. This mechanism allows you to guarantee that certain handlers are always invoked in sequence.
Check the SubscribingEventProcessor class/javadoc for more details.



Thank you, I will take a look in to this.