title: JMS TextMessage, JMS_BEA_SELECT message selector, transacted session and acknowledge modes
body: <p>My application is running under Tomcat with a number of Spring's <code>DefaultMessageListenerContainer</code> listening to a number of different JMS queues running under Oracle 11g Weblogic server.</p>
  
  <p><code>DefaultMessageListenerContainer</code> configuration is.. well.. default with <code>sessionTransacted = false</code> and <code>sessionAcknowledgeMode = AUTO_ACKNOWLEDGE</code>. The type of messages my application receives is <code>javax.jms.TextMessage</code>. The actual body of the message (<code>message.getText()</code>) is an XML string.</p>
  
  <p>I was faced with a problem when a number of application instances (dev boxes, test boxes, etc) needed to be pointed to the same JMS server, so once message comes to the queue it is unknown which server will consume it (I believe the one that runs <code>receive()</code> method first). The problem is that any given application instance is only interested in messages dedicated to that particular application instance, so with a current configuration most of the messages get lost (consumed by other application instances and ignored in message processing business logic).</p>
  
  <p>I have no control on JMS server implementation, but I can force it to set a particular XML element in the message body to an application instance specific value, so I can read it and decide what application instance should consume it.</p>
  
  <p>The most natural way to do that would be setting <code>messageSelector</code> property on <code>DefaultMessageListenerContainer</code> so decision is made on JMS server which consumer should receive what message. I also learned about Weblogic specific <code>JMS_BEA_SELECT</code> message selector expression that works with XML message types. Unfortunately it doesn't seem to work with <code>javax.jms.TextMessage</code> messages with XML payload (or at least I couldn't make it to work). I was trying the following expression with no luck:</p>
  
  <pre><code>&lt;property name="messageSelector" value="JMS_BEA_SELECT('xpath', '//Event/CorrelationID/text()') = 'MY_SELECTOR_TEST_3'"/&gt;
  </code></pre>
  
  <p>According to <a href="http://placementpapers.net/helpingroot/paper/BEA-WebLogic-Interview-Questions-And-Answer-Set-8" rel="nofollow">this article</a> the other options are:</p>
  
  <ol>
  <li>Use a transacted session, then rollback the session so the message will go back to the queue and can be consumed by other application instance.</li>
  <li>Use Session.CLIENT_ACKNOWLEDGE when creating a session, then recover the session so the message will go back to the queue and can be consumed by other application instance.</li>
  </ol>
  
  <p>I understand that I need to set <code>sessionTransacted</code> and <code>sessionAcknowledgeMode</code> on <code>DefaultMessageListenerContainer</code> to non-default values (what values?) and then rollback the session in the message processor code (option 1) or don't call <code>message.acknowledge()</code> (option 2).</p>
  
  <p>It looks like <code>DefaultMessageListenerContainer</code> controls message processing / session life cycle. How can I customise it?</p>