0
votes

I am using an ActiveMq embedded broker. I am using pub/sub model. I have multiple listeners subscribed to the topic. I am using Default Message listener container.

So I started getting statistics of the topic and the subscribers.

The statistic for number of messages in Topic is always zero.

    DestinationStatistics statistics = destination
                        .getDestinationStatistics();
    LOG.info("The message count in topic is" + destination.getMessages().count())

The 'message count in topic is' always zero, as far as I saw. So now I got the statistics for the consumers to the destination. The destination is topic I am using.

    Iterator<Subscription> it = destination.getConsumers().iterator();
    while(it.hasNext()){
    Subscription s= it.next();
    LOG.info(s.getPendingQueueSize()+ ""+ s.getEnqueueCounter()+""+s.getDequeueCounter())
    }

I saw that these stats for each consumer reflect the messages I have sent as part of pub/sub.

So how does this whole process work?

I publish a message, the broker immediately pushes the message to the subscriber, the subscribers maintain the messages of their respective consumers. Hence the message count in topic is always zero and the stats for each consumer give an idea of the messages received by the broker.

Can someone explain the process and how the stats should work?

1
Is you topic auto-ack? If so then it will immediately send all messages to consumer. If your topic is durable and your consumer is not running, then you should see messages on the topic.dmossakowski

1 Answers

0
votes

A topic is just an adress. It cannot hold messages, just dispatch messages to subscribers. Hence, it does not have a message count.

Subscribers can hold messages for some time until consumed by the consumer.

You can see statistics about number of enqueued messages to the topic as well as number of messages waiting to be dispatched using either the ActiveMQ Web Console or through JMX/Jolokia API.