【问题标题】:ActiveMQ not returning message when queue has n number of pending messages当队列有 n 条待处理消息时,ActiveMQ 不返回消息
【发布时间】:2014-09-24 23:54:20
【问题描述】:

环境/背景:

使用 PHP Stomp 库从 ActiveMQ (v5.4.3) 发送和接收消息。

步骤:

  1. 客户端将带有回复和相关 ID 标头的消息发送到请求队列(例如 /queue/request)
  2. 订阅响应队列(例如 /queue/response)
  3. 阅读框架
  4. 确认
  5. 退订

当没有待处理消息或待处理消息 200 时,消息不会被传递。该过程一直等到超时,最后超时而没有响应。超时后我可以看到消息(使用管理 UI)。这是我用于此案例的代码:

<?php

// make a connection
$con = new Stomp("tcp://localhost:61616");
// Set read timeout.
$con->setReadTimeout(10);

// Prepare request variables.
$correlation_id = rand();    
$request_queue = '/queue/com.domain.service.request';
$response_queue = '/queue/com.domain.service.response';
$selector =  "JMSCorrelationID='$correlation_id'";
$headers = array('correlation-id' => $correlation_id, 'reply-to' => $response_queue);
$message = '<RequestBody></RequestBody>';

// send a message to the queue.
$con->send($request_queue, $message, $headers);

// subscribe to the queue
$con->subscribe($response_queue, array('selector' => $selector, 'ack' => 'auto'));

// receive a message from the queue
$msg = $con->readFrame();

// do what you want with the message
if ( $msg != null) {
    echo "Received message with body\n";
    var_dump($msg);
    // mark the message as received in the queue
    $con->ack($msg);
} else {
    echo "Failed to receive a message\n";
}
unset($con);

其他发现:

  1. 从一个文件(比如从 sender.php)发送消息并使用另一个脚本(比如 receiver.php)接收工作正常。

  2. 允许在同一个请求队列中发送超过 1000 条消息(并最终处理并放入响应队列中)。所以看起来不像是内存问题。

  3. 很有趣,在等待超时时,如果我在管理 UI 上浏览队列,我会得到响应。

  4. 默认情况下,我使用的 stomp 代理将预取大小设置为 1。

【问题讨论】:

    标签: php jms activemq stomp


    【解决方案1】:

    在不了解更多信息的情况下,我的猜测是您有多个消费者,其中一个正在其预取缓冲区中占用消息,我认为默认大小为 1000。要调试这种情况,通常最好查看 Web 控制台或连接 jconsole 并检查 Queue MBean 以查看正在运行的消息、消费者数量等的统计信息。

    【讨论】:

    • 感谢您的回答@Tim。在我目前的情况下,只有一个消费者,预取为 1。我将尝试按照您指定的设置调试模式。
    【解决方案2】:

    回答我自己的问题。

    我面临的问题正是http://trenaman.blogspot.co.uk/2009/01/message-selectors-and-activemq.html 中描述的问题,解决方案是增加ActiveMQ and maxPageSize 中指定的maxPageSize

    您可以匹配到 200 不是一个可变数字,而是 maxPageSize 的默认值。

    更多参考资料:

    1. http://activemq.2283324.n4.nabble.com/Consumer-is-not-able-to-pick-messages-from-queue-td2531722.html

    2. https://issues.apache.org/jira/browse/AMQ-2217

    3. https://issues.apache.org/jira/browse/AMQ-2745

    【讨论】:

      猜你喜欢
      • 2012-11-08
      • 2016-11-20
      • 2019-06-02
      • 2015-06-18
      • 1970-01-01
      • 2017-10-07
      • 2022-01-14
      • 2015-12-13
      • 1970-01-01
      相关资源
      最近更新 更多