Abzal Kalimbetov
Abzal Kalimbetov

Reputation: 505

How to get properly all queue messages from RabbitMQ in Spring?

I am using Spring, Spring-Websocket, STOMP for my application, and RabbitMQ as broker. I need to log all messages going through RabbitMQ to Postgresql tables. I know that I can write @MessageMapping in Spring and log there, but my problem is that some clients talk to RabbitMQ directly through MQTT protocol, and Spring does not support it yet (https://jira.spring.io/browse/SPR-12581). Moreover browser clients talk through Spring to RabbitMQ using STOMP protocol.

RabbitMQ allows to track all messages using Firehose tracer. How to properly listen to amq.rabbitmq.trace topic from Spring? Or do I need to write separate Java app as consumer?

Upvotes: 6

Views: 1920

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

The Spring AMQP is for you!

You bind some custom queue to to that amq.rabbitmq.trace with appropriate pattern (e.g. publish.#) and configure SimpleMessageListenerContainer to receive messages from that queue.

It can be done even with pretty simple config: @EnableRabbit and @RabbitListener on some POJO method. Anyway the Binding @Bean must be there to attache your queue to that exchange.

Upvotes: 1

Related Questions