How do we hook into before/After message processing using @RabbitListener

后端 未结 2 1458
死守一世寂寞
死守一世寂寞 2021-01-02 01:46

Problem: I am migrating from MessageListener interface impl to @RabbitListener. I had logic like this where I was doing \"pre\" and \"post\" message process

相关标签:
2条回答
  • 2021-01-02 02:17

    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?

    0 讨论(0)
  • 2021-01-02 02:43

    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.

    0 讨论(0)
提交回复
热议问题