title: How to setup ActiveMQ Artemis redelivery policy not to block the queue
body: <p><strong>Background</strong></p>
  
  <p>I have a JMS message queue on Apache Artemis 2.7.0.redhat-00056. The broker is configured with a <code>redelivery-delay</code> of 10 minutes. If I publish a message to the queue and it fails on the consumer then it goes back to the queue as a scheduled message to be delivered in 10 minutes time. Any subsequent messages that are published are processed straightaway, so the queue is not blocked by the scheduled message.</p>
  
  <p>If a number of messages are sent in quick succession then what happens is they all fail and get scheduled for 10 minutes time. In this case it looks like Artemis is  trying to preserve the message order.</p>
  
  <p><strong>Documentation</strong></p>
  
  <p>The docs on redelivery say the following:</p>
  
  <blockquote>
    <p>Other subsequent messages will be delivery regularly, only the cancelled message will be sent asynchronously back to the queue after the delay.</p>
  </blockquote>
  
  <p><a href="https://activemq.apache.org/components/artemis/documentation/latest/undelivered-messages.html" rel="nofollow noreferrer">Redelivery documentation</a></p>
  
  <p><strong>Problem</strong></p>
  
  <p>It seems inconsistent to me that if you publish the messages in close succession that Artemis appears to preserve the order, whereas if there is a slight delay between messages then the queue does not block and only the failed messages are scheduled with a delay (as per the docs).</p>
  
  <p>I'm trying to find a solution so that if one message fails and needs to be redelivered in 10 minutes that it doesn't block subsequent messages.</p>
  
  <p><strong>Example</strong>   </p>
  
  <p>It doesn't need anything special to recreate this. As described you just need to send some messages in quick succession to a queue that has a redelivery policy on the broker. I've been testing with a basic example as follows:</p>
  
  <p>Spring boot app that produces five messages on startup.</p>
  
  <pre><code>@SpringBootApplication
  public class ArtemisTestApplication
  {
  
      private Logger logger = LoggerFactory.getLogger(ArtemisTestApplication.class);
  
      @Autowired
      private JmsTemplate jmsTemplate;
  
      @PostConstruct
      public void init()
      {
          send("Message1");
          send("Message2");
          send("Message3");
          send("Message4");
          send("Message5");
      }
  
      public void send(String msg)
      {
          logger.debug("Sending message :{}", msg);
          jmsTemplate.convertAndSend("jms.queue.TestQueue", msg);
      }
  
      public static void main(String[] args)
      {
          SpringApplication.run(ArtemisTestApplication.class, args);
      }
  
  }
  </code></pre>
  
  <p>Consume messages and throw an error to trigger the redelivery policy.    </p>
  
  <pre><code>@Component
  public class TestConsumer
  {
      private Logger logger = LoggerFactory.getLogger(TestConsumer.class);
  
      @JmsListener(destination = "jms.queue.TestQueue")
      public void receive(TextMessage message) throws JMSException
      {
          logger.debug("Message received: {}", message.getText());
          throw new RuntimeException("Force redelivery policy");
      }
  }
  </code></pre>
  
  <p>The app was generated using the <a href="https://start.spring.io/" rel="nofollow noreferrer">spring boot initializr</a>. Other than giving it a name, the only thing of note selected was the artemis dependancy under messaging.</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-artemis&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>In application.properties I have configured the connection properties to the locally running instance of Artemis.</p>
  
  <pre><code>spring.artemis.mode=native
  spring.artemis.host=localhost
  spring.artemis.port=61616
  spring.artemis.user=
  spring.artemis.password=
  </code></pre>
  
  <p>And on the broker I have configured the queue with a redelivery policy. Note: I set the delay to 0 here and the problem still occurs in that all messages are blocked until the first message has had three attempts and been moved to the DLQ. If you change the delay to a positive number then you see all five messages are scheduled for delivery later.</p>
  
  <pre><code>&lt;address-settings&gt;      
      &lt;address-setting match="jms.queue.TestQueue"&gt;            
          &lt;dead-letter-address&gt;DLQ&lt;/dead-letter-address&gt;                      
          &lt;redelivery-delay&gt;0&lt;/redelivery-delay&gt;    
          &lt;max-delivery-attempts&gt;3&lt;/max-delivery-attempts&gt;
      &lt;/address-setting&gt;    
    &lt;/address-settings&gt;
  
  &lt;addresses&gt;     
      &lt;address name="DLQ"&gt;            
          &lt;anycast&gt;               
            &lt;queue name="DLQ" /&gt;            
          &lt;/anycast&gt;         
        &lt;/address&gt;       
        &lt;address name="jms.queue.TestQueue"&gt;            
          &lt;anycast&gt;               
            &lt;queue name="jms.queue.TestQueue" /&gt;            
          &lt;/anycast&gt;         
        &lt;/address&gt;                      
  &lt;/addresses&gt;
  </code></pre>