title: Spring JMSTemplate receive all messages in one transaction
body: <p>I am trying to get all messages from the queue in synchronous mode using Spring JMSTemplate.receive(String) method.</p>
  
  <p>The problem is that I get always only one message. Here is the code:</p>
  
  <pre><code>@Transactional
  public List&lt;Message&gt; receiveAllFromQueue(String destination) {
    List&lt;Message&gt; messages = new ArrayList&lt;Message&gt;();
    Message message;
    while ((message = queueJmsTemplate.receive(destination)) != null) {
      messages.add(message);
    }
    return messages;
  }
  </code></pre>
  
  <p>If I remove @Transactional annotation I get all messages, but all is done out of transaction so if later during processing these messages there is an exception the messages will be lost.</p>
  
  <p>Here is a definition of my JMSTemplate bean.</p>
  
  <pre><code>&lt;bean id="queueJmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
      &lt;property name="pubSubDomain" value="false" /&gt;
      &lt;property name="receiveTimeout" value="1" /&gt;
     &lt;property name="sessionTransacted" value="true" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>What I want to achieve is to have one transaction and within this transaction I want to get all pending messages.</p>