title: activemessaging with stomp and activemq.prefetchSize=1
body: <p>I have a situation where I have a single activemq broker with 2 queues, Q1 and Q2.  I have two ruby-based consumers using activemessaging.  Let's call them C1 and C2.  Both consumers subscribe to each queue.  I'm setting activemq.prefetchSize=1 when subscribing to each queue.  I'm also setting ack=client.</p>
  
  <p>Consider the following sequence of events:</p>
  
  <p>1) A message that triggers a long-running job is published to queue Q1.  Call this M1.</p>
  
  <p>2) M1 is dispatched to consumer C1, kicking off a long operation.</p>
  
  <p>3) Two messages that trigger short jobs are published to queue Q2.  Call these M2 and M3.</p>
  
  <p>4) M2 is dispatched to C2 which quickly runs the short job.</p>
  
  <p>5) M3 is dispatched to C1, even though C1 is still running M1.  It's able to dispatch to C1 because prefetchSize=1 is set on the queue subscription, not on the connection.  So the fact that a Q1 message has already been dispatched doesn't stop one Q2 message from being dispatched.</p>
  
  <p>Since activemessaging consumers are single-threaded, the net result is that M3 sits and waits on C1 for a long time until C1 finishes processing M1.  So, M3 is not processed for a long time, despite the fact that consumer C2 is sitting idle (since it quickly finishes with message M2).</p>
  
  <p>Essentially, whenever a long Q1 job is run and then a whole bunch of short Q2 jobs are created, exactly one of the short Q2 jobs gets stuck on a consumer waiting for the long Q1 job to finish.</p>
  
  <p>Is there a way to set prefetchSize at the connection level rather than at the subscription level?  I really don't want any messages dispatched to C1 while it is processing M1.  The other alternative is that I could create a consumer dedicated to processing Q1 and then have other consumers dedicated to processing Q2.  But, I'd rather not do that since Q1 messages are infrequent--Q1's dedicated consumers would sit idle most of the day tying up memory.</p>