Problem: I am migrating from MessageListener interface impl to @RabbitListener. I had logic like this where I was doing \"pre\" and \"post\" message process
The inheritance isn't possible here because annotation processing on the POJO methods and MessageListener
implementation are fully different stories.
Using MessageListener
you fully have control around the target behavior and the container
.
With the annotations you deal only with the POJO, framework-free code. The particular MessageListener
is created on the background. And that one fully based on the annotated method.
I'd say we can achieve your requirement using Spring AOP Framework.
See the recent question and its answers on the matter: How to write an integration test for @RabbitListener annotation?
Correction
You can use the advice chain in the SimpleRabbitListenerContainerFactory to apply an around advice to listeners created for @RabbitListener
; the two arguments are the Channel
and Message
.
If you only need to take action before calling the listener, you can add MessagePostProcessor
(s) to the container afterReceivePostProcessors
.