[英]ActiveMQ not returning message when queue has n number of pending messages
環境/背景:
使用PHP Stomp庫從ActiveMQ(v5.4.3)發送和接收消息。
腳步:
當沒有未決消息或未決消息<n時,上述步驟可以正常工作。 在我的情況下,n = 200。 當待處理消息的數量> 200時,該消息將不發送。 該過程一直等到超時,最后超時而沒有響應。 超時后,我可以看到該消息(使用管理界面)。 這是我在這種情況下使用的代碼:
<?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);
其他發現:
從一個文件發送消息(例如,從sender.php發送消息),並使用另一個腳本(例如,receiver.php)接收消息,可以正常工作。
允許在同一請求隊列中發送1000條以上的消息(並最終進行處理並放入響應隊列中)。 因此,它看起來不像是內存問題。
有趣的是,在等待超時的同時,如果我在管理UI上瀏覽隊列,則會收到響應。
默認情況下,我使用的腳踏代理將預取大小設置為1。
在不知道更多信息的情況下,您有多個使用者,並且正在將消息存儲在預取緩沖區中,我認為默認大小為1000。 要調試這種情況,通常最好查看Web控制台或與jconsole連接並檢查Queue MBean,以查看運行中消息的統計信息,使用方數量等。
回答我自己的問題。
我面臨的問題正是http://trenaman.blogspot.co.uk/2009/01/message-selectors-and-activemq.html中描述的問題,解決方案是按照ActiveMQ和maxpagesize可
您可以匹配到200不是可變數字,而是maxPageSize的默認值。
更多參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.