Environment/Background:
环境/背景:
Using PHP Stomp library to send and receive message from ActiveMQ (v5.4.3).
使用PHP Stomp库从ActiveMQ (v5.4.3)发送和接收消息。
Steps:
步骤:
- Client sends a message with reply-to & correlation-id headers to request queue (say /queue/request)
- 客户端向请求队列发送具有应答和关联id头的消息(例如/queue/request)
- Subscribe to the response queue (say /queue/response)
- 订阅响应队列(例如/队列/响应)
- Read frame
- 阅读框架
- ack
- 消
- unsubscribe
- 退订
The above steps works fine when there is no pending message or pending message < n. In my case, n =200. When the number of pending message is > 200, the message is not delivered. 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:
当没有等待消息或等待消息< n时,上述步骤可以正常工作。在我的例子中,n =200。当挂起消息的数量为>200时,该消息不会被传递。进程等待超时,最后超时而没有响应。超时后我可以看到消息(使用admin 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);
Other findings:
其他的发现:
-
Sending messages from one file (say from sender.php) and receive using another script (say receiver.php) working fine.
从一个文件(比如sender.php)发送消息,然后使用另一个脚本(比如receiver.php)接收消息,效果很好。
-
Allows to send more than 1000 message in the same request queue(and eventually processed and placed in response queue). So it doesn't look like memory issue.
允许在同一个请求队列中发送超过1000条消息(并最终处理并放置在响应队列中)。看起来不像是记忆问题。
-
Funny enough, while waiting for timeout, if I browse the queue on admin UI, I get the response.
有趣的是,在等待超时时,如果我在admin UI上浏览队列,就会得到响应。
-
By default, the stomp broker that I use set the prefetch size to 1.
默认情况下,我使用的stomp代理将预取大小设置为1。
2 个解决方案
#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. 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.
我不知道的是,您有多个消费者,其中一个在它的预取缓冲区中占用消息,我认为默认大小是1000。要调试这样的情况,最好查看web控制台或连接jconsole并检查队列MBean,以查看航班消息的统计信息、用户数量等。
#2
1
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- selectorand -activemq中所描述的问题。html和解决方案是增加ActiveMQ和maxPageSize中指定的maxPageSize
As you can match that the 200 is not a varying number, but the default value of maxPageSize.
正如您可以匹配的那样,200不是一个变化的数字,而是maxPageSize的默认值。
More references:
更多的引用:
-
http://activemq.2283324.n4.nabble.com/Consumer-is-not-able-to-pick-messages-from-queue-td2531722.html
-
https://issues.apache.org/jira/browse/AMQ-2217
https://issues.apache.org/jira/browse/amq - 2217
-
https://issues.apache.org/jira/browse/AMQ-2745
https://issues.apache.org/jira/browse/amq - 2745
#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. 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.
我不知道的是,您有多个消费者,其中一个在它的预取缓冲区中占用消息,我认为默认大小是1000。要调试这样的情况,最好查看web控制台或连接jconsole并检查队列MBean,以查看航班消息的统计信息、用户数量等。
#2
1
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- selectorand -activemq中所描述的问题。html和解决方案是增加ActiveMQ和maxPageSize中指定的maxPageSize
As you can match that the 200 is not a varying number, but the default value of maxPageSize.
正如您可以匹配的那样,200不是一个变化的数字,而是maxPageSize的默认值。
More references:
更多的引用:
-
http://activemq.2283324.n4.nabble.com/Consumer-is-not-able-to-pick-messages-from-queue-td2531722.html
-
https://issues.apache.org/jira/browse/AMQ-2217
https://issues.apache.org/jira/browse/amq - 2217
-
https://issues.apache.org/jira/browse/AMQ-2745
https://issues.apache.org/jira/browse/amq - 2745