How to throttle message subscription for a spring-amqp ascyn consumer?

橙三吉。 提交于 2019-12-12 02:36:15

问题


I have an async consumer configured via the spring-amqp framework:

<listener-container
    connection-factory="connectionFactory"
    message-converter="jsonMessageConverter"
    xmlns="http://www.springframework.org/schema/rabbit">
    <listener ref="requestHandler" method="handleMessage" queue-names="blah" />
</listener-container>

An external event from a 3rd party app indicates to my server that its ready to process data, at such a time I would like to take messages from the queue that I'm subscribed to and process them against the 3rd party app.

The job of my handleMessage method is to queue-up messages until the ready event from the 3rd party app is received. But I don't want to queue up too many, it would defeat the purpose of having RabbitMQ in the middle. Also, any optimization that can be achieved by NOT explicitly fetching messages when the ready event is received, would be lost.

Is there some way to indicate that I want to pause the subscription once an upperbound has been reached? Would QueueingConsumer be somehow relevant here?


回答1:


Sounds like SimpleMessageListenerContainer.stop() is enough for you. Add an id attribute to your configuration and invoke that method when you need. And further you can invoke SimpleMessageListenerContainer.start() again.



来源:https://stackoverflow.com/questions/20497307/how-to-throttle-message-subscription-for-a-spring-amqp-ascyn-consumer

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