title: Message Ordering Across Queues
body: <p>I have a scenario in my RabbitMQ setup that I'm curious about how to solve. The diagram below illustrates it (exchanges and most queues removed for succinctness):</p>
  
  <p><img src="https://i.stack.imgur.com/qJMye.png" alt="enter image description here"></p>
  
  <p><strong>Scenario</strong></p>
  
  <ol>
  <li>Producer creates message A(1), it is received by the top consumer, which begins processing the message.</li>
  <li>Producer creates message A(2), it is received by the bottom consumer (assuming both consumers are on a round-robin exchange).</li>
  <li>The bottom consumer publishes message B(2), which is put into Message B consumer's queue</li>
  <li>The poor slow top consumer finally finishes and emits its message B(1).</li>
  </ol>
  
  <p><strong>Problem</strong></p>
  
  <p>If we assume that B consumer cannot be made idempotent, how do we ensure the result of both B messages are applied in the correct order? </p>
  
  <p>I had thought of using a timestamp that is applied to the initial publish of message A, and having the consumer maintain a timestamp of last change, rejecting any timestamps before that time, but that only works if each message causes the exact same kind of change and requires a lot of tracking.</p>
  
  <p>Other ideas for how to approach this would be appreciated. Thanks!</p>