ActiveMQ消费者执行延迟

发布于 2024-10-03 13:28:07 字数 968 浏览 1 评论 0原文

我看到一个问题,队列没有备份,但消费者实际执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被翻牌 2024-10-10 13:28:07

您对消费者是否立即从队列中提取消息有多大把握? ActiveMQ 提供了 JMSActiveMQBrokerInTimeJMSActiveMQBrokerOutTime 属性,您可以使用它们来确认这一点(请参阅ActiveMQ 消息属性)。

How certain are you that the consumer is pulling the message off the queue immediately? ActiveMQ provides the JMSActiveMQBrokerInTime and JMSActiveMQBrokerOutTime properties you can use to confirm this (see ActiveMQ message properties).

瑾夏年华 2024-10-10 13:28:07

事实证明,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文