Multi-method Listeners

Starting with version 1.5.0, you can specify the @RabbitListener annotation at the class level. Together with the new @RabbitHandler annotation, this lets a single listener invoke different methods, based on the payload type of the incoming message. This is best described using an example:

@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) {

In this case, the individual @RabbitHandler methods are invoked if the converted payload is a Thing2, a Cat, or a Hat. You should understand that the system must be able to identify a unique method based on the payload type. The type is checked for assignability to a single parameter that has no annotations or that is annotated with the @Payload annotation. Notice that the same method signatures apply, as discussed in the method-level @RabbitListener (described earlier).

Starting with version 2.0.3, a @RabbitHandler method can be designated as the default method, which is invoked if there is no match on other methods. At most, one method can be so designated.

Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra™, and Apache Geode™ are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java™, Java™ SE, Java™ EE, and OpenJDK™ are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners.