title: RabbitMQ Spring Boot AMQP - consume with concurrent threads
body: <p>I want my app to handle multiple messages received from RabbitMQ concurrently.
  I have tried probably all the google-page-1 solutions but it won't work.
  Here is my setup:</p>
  
  <p>POM.xml</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.10.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  .
  .
  .
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.amqp&lt;/groupId&gt;
      &lt;artifactId&gt;spring-rabbit&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>application.properties:</p>
  
  <pre><code>#############################
  #         RabbitMQ          #
  #############################
  #AMQP RabbitMQ configuration 
  spring.rabbitmq.host=zzzzzzzz
  spring.rabbitmq.port=5672
  spring.rabbitmq.username=zzzzzzz
  spring.rabbitmq.password=zzzzzzz
  #Rabbit component names
  com.cp.neworder.queue.name = new-order-queue-stg
  com.cp.neworder.queue.exchange = new-order-exchange-stg
  com.cp.completedorder.queue.name = completed-order-queue
  com.cp.completedorder.queue.exchange = completed-order-exchange
  #Rabbit MQ concurrect consumers config
  spring.rabbitmq.listener.simple.concurrency=3
  spring.rabbitmq.listener.simple.retry.initial-interval=3000
  </code></pre>
  
  <p>Configuration file:</p>
  
  <pre><code>@Configuration
  public class RabbitMQConfig {
  
      @Value("${com.cp.neworder.queue.name}")
      private String newOrderQueueName;
      @Value("${com.cp.neworder.queue.exchange}")
      private String newOrderExchangeName;
  
      @Bean
      Queue queue() {
          return new Queue(newOrderQueueName, true);
      }
  
      @Bean
      TopicExchange exchange() {
          return new TopicExchange(newOrderExchangeName);
      }
  
      @Bean
      Binding binding(Queue queue, TopicExchange exchange) {
          return BindingBuilder.bind(queue).to(exchange).with(newOrderQueueName);
      }
  
      @Bean
      SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
          SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
          container.setConnectionFactory(connectionFactory);
          container.setQueueNames(newOrderQueueName);
          container.setMessageListener(listenerAdapter);
          return container;
      }
  
      @Bean
      MessageListenerAdapter listenerAdapter(OrderMessageListener receiver) {
          return new MessageListenerAdapter(receiver, "receiveOrder");
      }
  
  }
  </code></pre>
  
  <p>My consumer class works as intended, it just processes one request at a time. How do I know?</p>
  
  <ol>
  <li>I save the process of my async requests in DB, so I can query how many are processing at the moment, and it's always just 1.</li>
  <li>I can look at the RabbitMQ Management platform, and I see that it's being dequeued one by one.</li>
  </ol>
  
  <p>What are the mistakes in my setup? How do I get it to work?</p>
  
  <p>Thanks.</p>