How to get number of unacknowledged messages on the broker?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get number of unacknowledged messages on the broker?

xabhi
Hi,

I want to get the number of unacknowledged messages on the broker. Below is the way I have implemented it currently. I am using BrokerPluginSupport which extends MutableBrokerFilter which has the send() and acknowledge() methods.

1. Keeping a counter which is increased in send() function - TotalSentMessages
2. Keeping a counter which is increased in acknowledge() function - TotalAckRecievedCount

TotalUnackedMessages = TotalSentMessages - TotalAckRecievedCount

I am getting this value close to 5.3 million which doesn't seem correct to me in my setup.

I can't use BrokerView.getTotalMessageCount() as it reports only messages held on queue, nothing about topic subcsribers.

Is there anything wrong in this method of calculating unacked messages? I believe that I am missing some thing here but not sure what?

Thanks,
Abhi
Reply | Threaded
Open this post in threaded view
|

Re: How to get number of unacknowledged messages on the broker?

Tim Bain
If you have a topic with N subscribers, it sounds like enqueuing a message
will increase the first counter by 1, and having all consumers consume it
will increase the second counter by N, which is probably not what you want.

Also make sure your code to increment is threadsafe (in this case,
AtomicLong should be all you need), else you may find your counts off
inexplicably.

I'd probably have approached it differently, using JMX to iterate over each
subscription for each topic and summing the number of unacknowledged
messages for each.  Note that because JMX is somewhat slow, the numbers
from my approach won't be exactly accurate (since message counts could
change after you get the stats for a subscriber but before you finish
collecting them all), so your approach will be more precise if you can find
the right place to put your first counter.

Tim
On Jun 10, 2015 4:50 AM, "xabhi" <[hidden email]> wrote:

> Hi,
>
> I want to get the number of unacknowledged messages on the broker. Below is
> the way I have implemented it currently. I am using BrokerPluginSupport
> which extends MutableBrokerFilter which has the send() and acknowledge()
> methods.
>
> 1. Keeping a counter which is increased in send() function -
> TotalSentMessages
> 2. Keeping a counter which is increased in acknowledge() function -
> TotalAckRecievedCount
>
> TotalUnackedMessages = TotalSentMessages - TotalAckRecievedCount
>
> I am getting this value close to 5.3 million which doesn't seem correct to
> me in my setup.
>
> I can't use BrokerView.getTotalMessageCount() as it reports only messages
> held on queue, nothing about topic subcsribers.
>
> Is there anything wrong in this method of calculating unacked messages? I
> believe that I am missing some thing here but not sure what?
>
> Thanks,
> Abhi
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-get-number-of-unacknowledged-messages-on-the-broker-tp4697616.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How to get number of unacknowledged messages on the broker?

xabhi
Hi,

I am not sure what to do when you say "using JMX to iterate over each subscription", Where will you do this inside a broker plugin? do you mean to create jmx connection and get those stats?
Can we not access those stats directly inside a broker plugin?

Thanks,
Abhi
Reply | Threaded
Open this post in threaded view
|

Re: How to get number of unacknowledged messages on the broker?

christopher.l.shannon
The ManagedRegionBroker keeps track of subscriptions.  Inside that broker
class it keeps track of queueSubscribers and topicSubscribers.  The maps
store SubscriptionView objects and they have a method called
getMessageCountAwaitingAcknowledgement() that you could use.

ManagedRegionBroker will be one of the brokers in the chain and you can get
access to it from a BrokerPlugin.

On Thu, Jun 11, 2015 at 5:31 AM, xabhi <[hidden email]> wrote:

> Hi,
>
> I am not sure what to do when you say "using JMX to iterate over each
> subscription", Where will you do this inside a broker plugin? do you mean
> to
> create jmx connection and get those stats?
> Can we not access those stats directly inside a broker plugin?
>
> Thanks,
> Abhi
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-get-number-of-unacknowledged-messages-on-the-broker-tp4697616p4697658.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How to get number of unacknowledged messages on the broker?

Tim Bain
The alternate approach I described would probably be taken from outside the
broker rather than from a broker plugin.  But the method Chris pointed out
to you seems like a good one for implementing this within a plugin.
On Jun 11, 2015 5:46 AM, "Christopher Shannon" <
[hidden email]> wrote:

> The ManagedRegionBroker keeps track of subscriptions.  Inside that broker
> class it keeps track of queueSubscribers and topicSubscribers.  The maps
> store SubscriptionView objects and they have a method called
> getMessageCountAwaitingAcknowledgement() that you could use.
>
> ManagedRegionBroker will be one of the brokers in the chain and you can get
> access to it from a BrokerPlugin.
>
> On Thu, Jun 11, 2015 at 5:31 AM, xabhi <[hidden email]> wrote:
>
> > Hi,
> >
> > I am not sure what to do when you say "using JMX to iterate over each
> > subscription", Where will you do this inside a broker plugin? do you mean
> > to
> > create jmx connection and get those stats?
> > Can we not access those stats directly inside a broker plugin?
> >
> > Thanks,
> > Abhi
> >
> >
> >
> > --
> > View this message in context:
> >
> http://activemq.2283324.n4.nabble.com/How-to-get-number-of-unacknowledged-messages-on-the-broker-tp4697616p4697658.html
> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >
>