title: Camel + ActiveMQ: Handling Two Distinct Concurrency Constraints With Competing Consumers
body: <p><strong>Problem:</strong></p>
  
  <p>Process a backlog of messages where each message has three headers "service", "client", and "stream".  I want to process the backlog of messages with maximum concurrency, but I have some requirements:</p>
  
  <ul>
  <li>Only 10 messages with the same service can be processing at once.</li>
  <li>Only 4 messages with the same service AND client can be processing at
  once. </li>
  <li>All messages with the same service AND client AND stream must
  be kept in order.</li>
  </ul>
  
  <hr>
  
  <p><strong>Additional Information:</strong></p>
  
  <p>I've been playing around with "maxConcurrentConsumers" along with the "JMSXGroupID" in a ServiceMix (Camel + ActiveMQ) context, and I seem to be able to get 2 out of 3 of my requirements satisfied.</p>
  
  <p>For example, if I do some content-based routing to split the backlog up into separate "service" queues (one queue for each service), then I can set the JMSXGroupID to (service + client + stream), and set maxConcurrentConsumers=10 on routes consuming from each queue.  This solves the first and last requirements, but I may have too many messages for the same client processing at the same time.</p>
  
  <p>Please note that if a solution requires a separate queue and route for every single combination of service+client, that would become unmanageable because there could be 10s of thousands of combinations.</p>
  
  <p>Any feedback is greatly appreciated!  If my question is unclear, please feel free to suggest how I can improve it.</p>