Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 272
Abzal Kalimbetov Avatar asked May 21 '15 09:05

Abzal Kalimbetov


People also ask

How do I get all messages from RabbitMQ?

exports = (connection, queue) => { init(connection, queue); return { getMessages: (queueName, cleanQueue) => new Promise((resolve) => { let messages = []; let i = 1; getChannel(). then((ch) => { ch. consume(queueName, (msg) => { messages. push(msg); console.

How do I get data from RabbitMQ queue?

In the Managed Service for ClickHouse cluster, create a table on the RabbitMQ engine. Send the test data to the RabbitMQ queue. Check that the test data is present in the Managed Service for ClickHouse cluster table. Delete the resources you created.

How do you consume messages from RabbitMQ?

In order to consume messages there has to be a queue. When a new consumer is added, assuming there are already messages ready in the queue, deliveries will start immediately. The target queue can be empty at the time of consumer registration. In that case first deliveries will happen when new messages are enqueued.


1 Answers

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.

like image 177
Artem Bilan Avatar answered Sep 19 '22 07:09

Artem Bilan