简体   繁体   English

当队列有n个待处理消息时,ActiveMQ不返回消息

[英]ActiveMQ not returning message when queue has n number of pending messages

Environment/Background: 环境/背景:

Using PHP Stomp library to send and receive message from ActiveMQ (v5.4.3). 使用PHP Stomp库从ActiveMQ(v5.4.3)发送和接收消息。

Steps: 脚步:

  1. Client sends a message with reply-to & correlation-id headers to request queue (say /queue/request) 客户端发送一条带有reply-to和correlation-id标头的消息以请求队列(例如/ queue / request)
  2. Subscribe to the response queue (say /queue/response) 订阅响应队列(例如/ queue / response)
  3. Read frame 读框
  4. ack ACK
  5. unsubscribe 退订

The above steps works fine when there is no pending message or pending message < n. 当没有未决消息或未决消息<n时,上述步骤可以正常工作。 In my case, n =200. 在我的情况下,n = 200。 When the number of pending message is > 200, the message is not delivered. 当待处理消息的数量> 200时,该消息将不发送。 The process waits till timeout and finally timeout without response. 该过程一直等到超时,最后超时而没有响应。 I can see the message (using admin UI) after timeout. 超时后,我可以看到该消息(使用管理界面)。 Here is the code that I'm using for this case: 这是我在这种情况下使用的代码:

<?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);

Other findings: 其他发现:

  1. Sending messages from one file (say from sender.php) and receive using another script (say receiver.php) working fine. 从一个文件发送消息(例如,从sender.php发送消息),并使用另一个脚本(例如,receiver.php)接收消息,可以正常工作。

  2. Allows to send more than 1000 message in the same request queue(and eventually processed and placed in response queue). 允许在同一请求队列中发送1000条以上的消息(并最终进行处理并放入响应队列中)。 So it doesn't look like memory issue. 因此,它看起来不像是内存问题。

  3. Funny enough, while waiting for timeout, if I browse the queue on admin UI, I get the response. 有趣的是,在等待超时的同时,如果我在管理UI上浏览队列,则会收到响应。

  4. By default, the stomp broker that I use set the prefetch size to 1. 默认情况下,我使用的脚踏代理将预取大小设置为1。

Without knowing more my guess is that you have multiple consumers and one is hogging the messages in it's prefetch buffer, the default size is 1000 I think. 在不知道更多信息的情况下,您有多个使用者,并且正在将消息存储在预取缓冲区中,我认为默认大小为1000。 To debug situations like this it's usually a good idea to look at the web console or connect with jconsole and inspect the Queue MBean to see the stats for in-flight messages, number of consumers etc. 要调试这种情况,通常最好查看Web控制台或与jconsole连接并检查Queue MBean,以查看运行中消息的统计信息,使用方数量等。

Answering my own question. 回答我自己的问题。

The problem I'm facing is exactly what is described in http://trenaman.blogspot.co.uk/2009/01/message-selectors-and-activemq.html and the solution is to increase the maxPageSize as specified in ActiveMQ and maxPageSize 我面临的问题正是http://trenaman.blogspot.co.uk/2009/01/message-selectors-and-activemq.html中描述的问题,解决方案是按照ActiveMQ和maxpagesize可

As you can match that the 200 is not a varying number, but the default value of maxPageSize. 您可以匹配到200不是可变数字,而是maxPageSize的默认值。

More references: 更多参考:

  1. http://activemq.2283324.n4.nabble.com/Consumer-is-not-able-to-pick-messages-from-queue-td2531722.html 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 https://issues.apache.org/jira/browse/AMQ-2217

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

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

相关问题 stomp-&gt; hasFrame()返回false,队列中有消息 - stomp->hasFrame() returning false with messages in the queue {"status":true,"message":"批量消息数 (1016) 超过允许的最大值 (1000)\n"} - {"status":true,"message":"Number of messages on bulk (1016) exceeds maximum allowed (1000)\n"} 消息禁用使用者时进行ActiveMQ / Stomp调试 - ActiveMQ/Stomp debug when a message disables a consumer 获取 Amazon SQS 队列中的消息数 - Get number of messages in an Amazon SQS Queue 使用STOMP从ActiveMQ队列读取时的非阻塞事务 - Non-blocking transactions when reading from ActiveMQ queue with STOMP 消息队列:当消息进入队列时,我们可以触发事件吗? - Message Queue: Can we trigger events when a message enters the queue? Twilio API:计数收到的消息数 - Twilio API: Count messages number has received ActiveMQ JobScheduler删除消息 - ActiveMQ JobScheduler remove message 我希望更新未读消息的数量,并在用户收到新消息时播放通知声音。 我正在使用PHP,MySql,Javascript - i want the number of unread messages to be updated and a notification sound played when a user receives new message. Am using PHP, MySql, Javascript 当消息发送回SQS时,Laravel队列工作程序作业失败 - Laravel queue worker jobs fail when messages are sent back to SQS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM