title: Spring-AMQP - routing based on message headers
body: <p>As per the documentation: <a href="https://docs.spring.io/spring-amqp/docs/2.2.5.RELEASE/reference/html/#async-annotation-driven" rel="nofollow noreferrer">https://docs.spring.io/spring-amqp/docs/2.2.5.RELEASE/reference/html/#async-annotation-driven</a></p>
  
  <p>We can have different handlers for messages based on it's converted class type like:</p>
  
  <pre><code>@RabbitListener(id="multi", queues = "someQueue")
  @SendTo("my.reply.queue")
  public class MultiListenerBean {
  
      @RabbitHandler
      public String thing2(Thing2 thing2) {
          ...
      }
  
      @RabbitHandler
      public String cat(Cat cat) {
          ...
      }
  
      @RabbitHandler
      public String hat(@Header("amqp_receivedRoutingKey") String rk, @Payload Hat hat) {
          ...
      }
  
      @RabbitHandler(isDefault = true)
      public String defaultMethod(Object object) {
          ...
      }
  
  }
  </code></pre>
  
  <p>This I believe won't be great in performance since it has to do a trial and error to cast the incoming payload. </p>
  
  <p>Instead, how to filter based on a condition say a header value? If header['operation']="order" then cast the message payload to Order class.</p>