title: 1 Consumer which takes from differents queues RabbitMQ
body: <p>I have 3 queues with different priority. I need that the consumer read from these queues. I declared and configured the priority of the queues on RabbitMQ web interface. I used <code>x-maximum-priority</code> parameter to set differents values (<a href="https://www.rabbitmq.com/priority.html" rel="nofollow noreferrer">https://www.rabbitmq.com/priority.html</a>). </p>
  
  <p>This is the code:</p>
  
  <pre><code>public static void main( String[] args ) throws IOException, TimeoutException, InterruptedException
  {
          .... 
          //Conection details
  
  
  
          System.out.println(" [x] Waiting ");
  
  
          Consumer consumer = new DefaultConsumer(channel) {
              @Override
              public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                  AMQP.BasicProperties replyProps = new AMQP.BasicProperties
                        .Builder()
                        .correlationId(properties.getCorrelationId())
                        .build();
  
  
  
                  String message = new String(body,"UTF-8");
  
                  System.out.println(message);
                  Thread.sleep(2000);//To simulate a big operation
  
  
  
  
                  channel.basicAck(envelope.getDeliveryTag(), false);
  
        };
  
  
        channel.basicConsume("high_priority", false, consumer);
        channel.basicConsume("medium_priority", false, consumer);             
        channel.basicConsume("low_priority", false ,consumer);                    
  
  
  
  }
  </code></pre>
  
  <p>but the consumer takes from the first queue and when is empty it takes from the second and when is empty it takes from the third.</p>
  
  <p>Is it a bad approach? Is it better use 3 consumers? Could works with consumer priorities? (<a href="https://www.rabbitmq.com/consumer-priority.html" rel="nofollow noreferrer">https://www.rabbitmq.com/consumer-priority.html</a>)</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I expect that the consumer takes the messages in differents order. I want that the consumer takes from high-priority-queue and occasionally takes from the others queues depending on the priority. I need to consume all messages in an intertwined way. I don't want that the low priority messages never be consume because high priority message overtakes always.</p>
  
  <p><strong>EXAMPLE:</strong></p>
  
  <p>I have 3 queues: high-priority, medium-priority, low-priority and for example i want that the consumer takes 10 messages from high-priority queue, 4 messages from medium-priority queue and 1 message from low-priority queue.</p>