簡體   English   中英

當隊列有n個待處理消息時,ActiveMQ不返回消息

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

環境/背景:

使用PHP Stomp庫從ActiveMQ(v5.4.3)發送和接收消息。

腳步:

  1. 客戶端發送一條帶有reply-to和correlation-id標頭的消息以請求隊列(例如/ queue / request)
  2. 訂閱響應隊列(例如/ queue / response)
  3. 讀框
  4. ACK
  5. 退訂

當沒有未決消息或未決消息<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);

其他發現:

  1. 從一個文件發送消息(例如,從sender.php發送消息),並使用另一個腳本(例如,receiver.php)接收消息,可以正常工作。

  2. 允許在同一請求隊列中發送1000條以上的消息(並最終進行處理並放入響應隊列中)。 因此,它看起來不像是內存問題。

  3. 有趣的是,在等待超時的同時,如果我在管理UI上瀏覽隊列,則會收到響應。

  4. 默認情況下,我使用的腳踏代理將預取大小設置為1。

在不知道更多信息的情況下,您有多個使用者,並且正在將消息存儲在預取緩沖區中,我認為默認大小為1000。 要調試這種情況,通常最好查看Web控制台或與jconsole連接並檢查Queue MBean,以查看運行中消息的統計信息,使用方數量等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM