difference between usage of @RabbitListener() and usage of DirectMessageListenerContainer in consuming from a rabbitMQ in springboot

Viewed 345

I am trying to configure concurrent consumers in spring to consume messages from RabbitMQ, in order to achieve that i have configured consumers in two ways

1.annotated a method with @RabbitListener(queues = "name of queue")

2.implementing "MessageListener" interface and overriding onMessage(Message message)

In my case both the ways worked fine, but i am unable to figure out what is the advantage/disadvantage of using @RabbitListener() for starting a consumer over the other way.

Also adding to that i have configured "DirectMessageListenerContainer" in my configuration and mapped it to "MessageListener" implementation to achieve concurrent consumers, my question here is can we do the same mapping for consumer implemented through @RabbitListener() and if so how. I couldnt find any source on how a consumer started with a @RabbitListener() annotated method can be configured with a "DirectMessageListenerContainer"

Any Help is appreciated.

1 Answers

@RabbitListener is simply a higher-level abstraction. It uses the listener container underneath.

When using spring boot, use the ...listener.type application property to specify which type of container you want.

The default is simple.

Related