ActiveMQ supports virtual destinations to magically link one or more queues to a topic.
It also supports JMX attributes to count messages going through the different destinations in a broker. There are both per-destination attributes (EnqueueCount and DequeueCount) and per-broker attributes (TotalEnqueueCount and TotalDequeueCount).
Unfortunately, these two features do not work well together.
Take for instance the following scenario:
- one topic (/topic/T)
- two virtual queues attached to it(/queue/Consumer.A.T and /queue/Consumer.B.T)
- one topic producer (PT1)
- two queue consumers on each virtual queue (CA1, CA2, CB1 and CB2)
When sending a single message, we get:
- /topic/T: EnqueueCount += 1 and DequeueCount += 0
- /queue/Consumer.A.T: EnqueueCount += 1 and DequeueCount += 1
- /queue/Consumer.B.T: EnqueueCount += 1 and DequeueCount += 1
- at broker level: TotalEnqueueCount += 3 and TotalDequeueCount += 2
This is not consistent: when the message leaves the topic to go to the virtual queues, DequeueCount (on the topic) does not change while EnqueueCount (on the queues) does change.
At broker level, TotalEnqueueCount gets incremented too much, giving the impression that 3 messages have been received.
The main question is: should the counters be incremented when a message is magically forwarded from the topic to the attached virtual queues?
I would argue that these counters should not change when messages move internally (i.e. along dashed lines). This way, we can continue to have TotalEnqueueCount being the sum of all EnqueueCount and at the same time representing the number of messages received (globally) by the broker. Idem for TotalDequeueCount and DequeueCount.
IMHO, these counters should only change when messages move along solid lines. If we want to track the internals (i.e. dashed lines) then we should have an additional counter, a bit like we already have ForwardCount for network of brokers.