title: How to guarantee message order in RabbitMQ (or any other asynchronous message queue service)
body: <p>I have a Java application which publishes events to RabbitMQ. It has one very important characteristic: message order must be preserved at all times. The consumer can handle duplicates, but it cannot handle when message <code>2</code> is enqueued before message <code>1</code>, so to say.</p>
  
  <p>I have been reading a lot about RabbitMQ lately, and I feel there is only solution to do this: set the channel in <code>confirm</code> mode (<a href="https://www.rabbitmq.com/confirms.html" rel="nofollow noreferrer">https://www.rabbitmq.com/confirms.html</a> - basically, it forces the broker to acknowledge the publication) and publish one by one. With one by one I mean that the message <code>2</code> is only published after RabbitMQ confirmed (via an asynchronous <code>ACK</code> response) that message <code>1</code> is actually well received and persisted.</p>
  
  <p>I tried this in a conceptual implementation, and while this works fine, it's uber slow, without exaggerating. Which makes sense: after all, we are now limiting our message rate to 1 message at a time.</p>
  
  <p>So this leads me to my question: are there other, more performant, ways to ensure that message ordering is always preserved (either in RabbitMQ or via different approaches)?</p>
  
  <p>Although my concern is RabbitMQ, I believe this question might be applied to any kind of asynchronous message queue service.</p>