Spring AMQP Reporting

旧时模样 提交于 2019-12-12 05:39:57

问题


We are using spring AMQP to listen to rabbitMQ for messages. I want to be able to report the metrics once we finished processing batch of messages, that means when we exhausts all the message in the queue. I m not sure how to do that in Spring AMQP. browsing spring document, it mentions advice chain to SimpleRabbitListenerContainerFactory, but that's mainly for RetryInterceptor. is there anyway allow me to report?


回答1:


There is nothing in the framework to notify the listener that there are no new messages available.

You could examine the queue using rabbitadmin to see a message count but that would be expensive to do it on every message delivery.

Some ideas:

You could schedule a task to run after some period when no messages are received (and cancel/reschedule each time a new message arrives).

You could have the sending system add a marker to the "last" message so the receiver knows the batch is complete.

Instead of using the message listener container, use RabbitTemplate.receive() (or receiveAndConvert()) which, by default, returns null when there are no messages in the queue. Call them in a loop until there are no messages. When that happens, issue your report, then go into a polling loop (with a sleep) to poll for the next "batch".



来源:https://stackoverflow.com/questions/32729709/spring-amqp-reporting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!