Spring JMS, custom event listener to identify when messages are added or removed from specific queues

Viewed 110

I've got a spring app that uses multiple queues to handle event processing. The app adds messages to these queues when specific events occur. When the messages are consumed they are removed implicitly. Example : RETRY_QUEUE to reprocess the message SUCCESS_QUEUE if the message gets through processing.

Internally I use @JmsListner to monitor the queue for incoming messages, how do I create a custom event handler that can be used to publish events when messages are added or removed from these queues ? I wanted to monitor these queues using prometheus gauges by inc() or dec() the queue size based on enqueue or dequeue events.

1 Answers

You can use Spring AOP principles to create point cuts to the JmsListener.onMessage() and JmsTemplate.send(..) methods to publish events. This approach will decouple your business logic with your event publish logic.

See also : @After, @Before, @AfterReturning, etc advices.

https://docs.spring.io/spring-framework/docs/2.5.6/reference/aop.html

Related