0

In out product we need to count occasionally the number of messages in a queue that hold a specific property value. The straight forward way is to use a queue browser with a selector. But:

  1. Is there a way to get this statistics without browsing all relevant messages? We don't need the data, only the count.
  2. If we do go for the queue browser approach, will it also browse messages that were consumed by some consumer, but not acknowledged yet?
Ofer B
  • 117
  • 1
  • 12

1 Answers1

0

There is not guaranteed way to count messages in a queue based on a selector. There are a number of reasons for this one of which is that the JMS Spec does not require that a QueueBrowser even return every message on a Queue. ActiveMQ won't return more than the number of messages that it can fit into memory so if you have a deep queue you won't have an accurate count. None of the management tools will do this for you either since it's not really ActiveMQ's job to be a database.

Here's some articles on messaging anti-patterns that you should read so you are better prepared for adventures in messaging.

Article 1 and Article 2

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • OK. I understand it's not a good design, but under the limitation of no more than 1000 non-acked messages of about 10kb each in the queue on every moment, and if I only want to know if there's at least 1 message with certain property value, is it still unreliable? – Ofer B Jul 19 '14 at 06:06
  • Yes, a message broker is not a database. See: http://stackoverflow.com/questions/16678685/activemq-and-maxpagesize – Tim Bish Jul 19 '14 at 11:08
  • So why is a queue browser available to begin with? Does it have any legitimate use? – Ofer B Jul 19 '14 at 12:56
  • You'd have to ask the authors of the the JMS spec. – Tim Bish Jul 19 '14 at 21:00