MessageConsumer::receiveNoWait() may return NULL even if messages are available
Issue
This problem affects C/C++ applications that use the CMS library to consume from an ActiveMQ destination. Consider the following piece of code, which polls a destination for a message and, if none is available, does some other work and then delays for a short time:
MessageConsumer *consumer = session->createConsumer (destination);
Message *m = consumer->receiveNoWait();
if (m)
{
// Process the message
}
else
{
// Do something else
sleep (1); // Wait before polling again
}
If a message is available, and if processing it is quick (milliseconds), then after the first successful call to receiveNoWait()
another call will be made very rapidly. This second call can fail -- that is, return NULL
even if messages are available. If the actions to be carried out in the event of a message not being available are lengthy (such as a the simple time delay shown above), then the whole application will run very slowly.
The problem can be demonstrated using a Java client in some circumstances, but it seems much less problematic in practice; possibly this is because the actual processing of the message in Java takes a bit longer.
Environment
- Red Hat JBoss Fuse/A-MQ
- 6.x
- Apache CMS library
- 3.8.x
- 3.9.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.