ActiveMQ消费者执行延迟
我看到一个问题,队列没有备份,但消费者实际执行 JMS 消息的时间在创建后 100 - 200 秒之间(通过 JMSTimestamp-CurrentTime 测量)。
队列的流量相当低,每分钟不到 30 条消息。我能够通过重新启动 ActiveMQ 来解决该问题,之后消息在创建后不到 1 毫秒内启动。
我使用的是 ActiveMQ 5.4.1,在 MDB 中完成的工作的正常总执行时间不到 2 毫秒。延迟时,ActiveMQ 日志中没有错误消息,CPU 较低且内存充足。
消费者似乎正在将消息从队列中拉出,但由于某种原因而搁置在队列上。
是否存在可能导致此问题的某些配置问题?
编辑:
我的MDB的第一行如下:
/* Check the time since this message was created versus processed */
try {
long secondsToProcess = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - aMessage.getJMSTimestamp());
if (secondsToProcess > 5) {
log.error("JMS Consumer Start Delay: " + secondsToProcess + " s" + " JMS Message took more then 5 seconds to be processed");
} else {
log.debug("JMS Consumer Start Delay: " + secondsToProcess + " s");
}
} catch (Exception e) {
log.error(e);
}
I'm seeing a problem where a Queue is not backed up however the time for the consumer to actually execute the JMS message is between 100 - 200 seconds from creation (as measured via the JMSTimestamp-CurrentTime).
The flow was fairly low to the queue, less then 30 messages a minute. I was able to resolve the issue by restarting ActiveMQ, after which messages were being started on less then 1ms from when they were created.
I'm using ActiveMQ 5.4.1 and the normal total execution time for the work being done in the MDB is less then 2ms. At the time of the delay, there were no error messages in the ActiveMQ log, CPU was low and had plenty of memory.
It seems like the consumer is pulling the message off the queue, but sitting on them for some reason.
Is there some configuration issue which could be causing this issue?
Edit:
The first line of my MDB is as follows:
/* Check the time since this message was created versus processed */
try {
long secondsToProcess = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - aMessage.getJMSTimestamp());
if (secondsToProcess > 5) {
log.error("JMS Consumer Start Delay: " + secondsToProcess + " s" + " JMS Message took more then 5 seconds to be processed");
} else {
log.debug("JMS Consumer Start Delay: " + secondsToProcess + " s");
}
} catch (Exception e) {
log.error(e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对消费者是否立即从队列中提取消息有多大把握? ActiveMQ 提供了
JMSActiveMQBrokerInTime
和JMSActiveMQBrokerOutTime
属性,您可以使用它们来确认这一点(请参阅ActiveMQ 消息属性)。How certain are you that the consumer is pulling the message off the queue immediately? ActiveMQ provides the
JMSActiveMQBrokerInTime
andJMSActiveMQBrokerOutTime
properties you can use to confirm this (see ActiveMQ message properties).事实证明,ActiveMQ 表现得很好,我的工作人员花了太长时间,因此备份了队列。我问题中的代码让我看到了这一点。
As it turns out, ActiveMQ was behaving just fine, my workers were taking too long hence backing up the queue. The code in my question allowed me to see that.