'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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dhanraj |
