简体   繁体   English

Java MQ消费者-如何控制消息消费率

[英]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).我正在使用 Spring JMS (DefaultMessageListenerContainer) 从 IBM MQ 读取消息,调用端点,并在成功时确认消息(客户端确认)。 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).假设微服务每秒消耗 1 条消息(最大值)。

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.我尝试将并发配置为 1 和轮询间隔(1000 毫秒),但这并不能控制消息的消耗速率。 That is if the entire process completes in 500 milliseconds then the service immediately picks up another message without waiting.也就是说,如果整个过程在 500 毫秒内完成,那么服务会立即接收另一条消息而无需等待。

For this scenario you can try using receive method that JmsTemplate provides.对于这种情况,您可以尝试使用 JmsTemplate 提供的接收方法。

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您可以将此逻辑包装在每 1 秒运行一次的调度程序中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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