title: Concurrent Synchronous Request-Reply with JMS/ActiveMQ - Patterns/Libraries?
body: <p>I have a web-app where when the user submits a request, we send a JMS message to a remote service and then wait for the reply. (There are also async requests, and we have various niceties set up for message replay, etc, so we'd prefer to stick with JMS instead of, say, HTTP)</p>
  
  <p>In <a href="http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html" rel="nofollow noreferrer">How should I implement request response with JMS?</a>, ActiveMQ seems to discourage the idea of either temporary queues per request or temporary consumers with selectors on the JMSCorrelationID, due to the overhead involved in spinning them up.</p>
  
  <p>However, if I use pooled consumers for the replies, how do I dispatch from the reply consumer back to the original requesting thread? </p>
  
  <p>I could certainly write my own thread-safe callback-registration/dispatch, but I hate writing code I suspect has has already been written by someone who knows better than I do.</p>
  
  <p>That ActiveMQ page recommends <a href="http://lingo.codehaus.org/" rel="nofollow noreferrer">Lingo</a>, which hasn't been updated since 2006, and <a href="http://camel.apache.org/spring-remoting.html" rel="nofollow noreferrer">Camel Spring Remoting</a>, which has been hellbanned by my team for its many gotcha bugs. </p>
  
  <p><em>Is there a better solution, in the form of a library implementing this pattern, or in the form of a different pattern for simulating synchronous request-reply over JMS?</em></p>
  
  <hr>
  
  <p>Related SO question:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/10786636/is-it-a-good-practice-to-use-jms-temporary-queue-for-synchronous-use">Is it a good practice to use JMS Temporary Queue for synchronous use?</a>, which suggests that spinning up a consumer with a selector on the JMSCorrelationID is actually low-overhead, which contradicts what the ActiveMQ documentation says. Who's right?</li>
  </ul>