简体   繁体   中英

Java MQ consumer - How to control message consumuption rate

I am using Spring JMS (DefaultMessageListenerContainer) to read messages from an IBM MQ, call an endpoint, and on success acknowledge the message (Client Ack). I need to control the rate at which the microservice calls the endpoint.

Is there any way to control the rate at which the consumer consume message? Say the microservice to consume 1 message per second (maximum).

I tried to configure the concurrency to 1 and poll interval (1000 milliseconds) but this does not control the rate at which messages are consumed. That is if the entire process completes in 500 milliseconds then the service immediately picks up another message without waiting.

For this scenario you can try using receive method that JmsTemplate provides.

i.e. jmsTemplate.receive(destination);

This lets you consume messages on demand. You can wrap this logic inside a scheduler which runs for every 1 second

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM