6

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?

Abzal Kalimbetov
  • 505
  • 7
  • 20
  • i don't understand you need to do it with spring. just configure rabbitmq to do it.. – Jaiwo99 May 21 '15 at 10:30
  • I need to write to DB to different tables – Abzal Kalimbetov May 21 '15 at 10:31
  • 1
    hmm.. then IMO you need an application to do it. you can certainly also put this consumer among other consumers. the docu from rabbitmq describes pretty well (https://www.rabbitmq.com/firehose.html), have a look, if your question is if spring amqp has this feature out of box, then the answer is no. – Jaiwo99 May 21 '15 at 10:38

1 Answers1

1

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Well. I'm not good in the Spring WebSocket Broker Relay and not sure that it will work, but you can try to `subscribe` like this: `/topic/exchange/amq.rabbitmq.trace/publish.#` – Artem Bilan May 21 '15 at 11:00
  • Is it ok to use AMQP to listen to Rabbit, and Stomp Broker relay to serve clients in one application? – Abzal Kalimbetov May 22 '15 at 03:40
  • 1
    Exactly! Spring STOMP support just takes care about WebSocket part in your applicaiton, but with Spring AMQP you do hard work around Broker queues and others. – Artem Bilan May 22 '15 at 05:11