1
votes

Environment/Background:

Using PHP Stomp library to send and receive message from ActiveMQ (v5.4.3).

Steps:

  1. Client sends a message with reply-to & correlation-id headers to request queue (say /queue/request)
  2. Subscribe to the response queue (say /queue/response)
  3. Read frame
  4. ack
  5. 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:

<?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.

  2. 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.

  3. Funny enough, while waiting for timeout, if I browse the queue on admin UI, I get the response.

  4. By default, the stomp broker that I use set the prefetch size to 1.

2

2 Answers

1
votes

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.

1
votes

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

As you can match that the 200 is not a varying number, but the default value of maxPageSize.

More references:

  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