Hi,
I am very curious about your thoughts on event message ordering when using RabbitMQ as transport. I could also need some help in filling in some gaps and correcting faulty assumptions in my reasoning.
What I would like is for all event messages to arrive at the handlers in the same order as they were published (which I assume is the same order as they are stored in the event store). Since there is no well defined inter aggregate order, the order within each aggragate is of course good enough.
Three different scenarios as I see it.
- Normal delivery, messagages are taken from the queue in batches of size prefetchCount and acked in batches of size txSize. In this case the events should arrive at event handlers in the same order as they are stored in the event store right? If they are not, do you have any more or less wild guesses of what could be the issue?
- An exception occurrs in an EventHandler method. The current transaction (if there is one) is rolled back and the messages up to and including the failed message is “nacked” by Spring AMQP and put at the end of the queue (according to the Spring AMQP documentation). Or is all of the remaining, non comitted messages in the prefetched batch “nacked”? Anyway this is a real problem since you will put a lot of messages out of order when throwing an exception, which would require some logic on the receiving side trying to reconstruct the proper order. I realize that this is more of a Spring AMQP question but I assume that you have given this some thought : ).
- The application crashes with a partially processed batch of event messages. In this case I assume the messages are just not acked towards Rabbit and according to http://www.rabbitmq.com/semantics.html, they should be back in the queue in publication order.
If my assumption in 1. is true then we’re in pretty good shape. Now we only need to to get rid of Spring AMQPs bad habbit of putting messages on the back of queue “for performance reasons” or implement some fulfledged reordiring mechanism on the receiving side, which seems like a lot of hassle that all clients should not have to deal with.
So, please do share your collected knowledge and thoughts on the topic : )
Cheers
Sebastian