title: Spring AMQP: how to avoid manual declaration of many queues?
body: <p>Having created a basic spring-amqp setup, I see that for every type of message I want to send (using message POJOs), I need to declare the queue in the spring config.</p>
  
  <p>So for every pair of these:</p>
  
  <pre><code>amqpTemplate.convertAndSend("queue1", new MessageType1(...));
  
  @RabbitListener(queues = "queue1")
  public void handleMessage(MessageType1 msg) {...}
  </code></pre>
  
  <p>I need an entry in the spring config like this:</p>
  
  <pre><code>&lt;rabbit:queue name="queue1"/&gt;
  </code></pre>
  
  <p>This seems redundant to me. If I think of the queues like HTTP urls, than it's enough to declare a controller with <code>@RequestMapping("/some-url")</code>, it's not necessary to than also declare <code>/some-url</code> elsewhere in the config.</p>
  
  <p>If eventually the application will have many types of messages going through the broker, that will just bloat the config.</p>
  
  <p>I see two ways to avoid this:</p>
  
  <ol>
  <li><p>Automatically declaring the queues for each annotated listener endpoint. i.e if there is an annotated listener endpoint <code>@RabbitListener(queues = "hello")</code>, then it can be inferred that a queue <code>hello</code> should be declared. I thought this might already be the case, but when I removed the queue from the context config, I got the following error:</p>
  
  <pre><code>WARN  BlockingQueueConsumer - Failed to declare queue:hello
  WARN  BlockingQueueConsumer - Queue declaration failed; retries left=2
  org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[hello]
      at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:479)
      at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:400)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1022)
  </code></pre></li>
  <li><p>Using different message POJOs on the same queue. So sending both <code>MessageType1</code> and <code>MessageType2</code> on <code>queue1</code>, each reaching a different endpoint, based on payload type. In effect this creates sort of a single "application queue", similar to a database schema:</p>
  
  <pre><code>@RabbitListener(queues = "queue1")
  public void handleMessage1(MessageType1 msg) {...}
  
  @RabbitListener(queues = "queue1")
  public void handleMessage2(MessageType2 msg) {...}
  </code></pre>
  
  <p>Trying this approach yielded an error.</p></li>
  </ol>
  
  <p>Is any of the above currently possible with spring-amqp (1.4.0), and if so how?</p>