activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sinus <>
Subject Re: How to find if the topic is empty ?
Date Thu, 13 Aug 2009 06:54:37 GMT

sinus wrote:
> Hello to everybody,
> I have a java application that uses activemq 5.2. A batch file starts the
> broker, create subscribers and register the listeners to the topic. The
> same bath is responsible for stoping the process. During the stop
> operation I must perform a check on the state of the topic. If there are
> some messages in the topic, the application must wait all the messages to
> be consumed and only after this, close the subscribers and the broker.
> So, how can I check the state of the topic on the presence of the messages
> in it ?
> Thanks.
> Serge.

Hello to everybody,
After 4-5 hours of googling in code search, I found the solution. My be this
test code it will be useful for somebody:

BrokerViewMBean broker;
        try {
            broker = brokerService.getAdminView();
        } catch (Exception e) {
            log.error("Can not get the adminview", e);            

        ObjectName[] topicsObjectNames = broker.getTopics();
        if (topicsObjectNames == null || topicsObjectNames.length == 0) {
            log.error("No topics found in adminview");
            throw new BaseException("No topics found in adminview");
        for (ObjectName topicObjectName : topicsObjectNames) {
(topicObjectName.getKeyProperty("Destination").equals("myTopic")) {
                MBeanServer mbeanServer = new
                TopicViewMBean topicViewMBean = (TopicViewMBean)
                        .newProxyInstance(mbeanServer, topicObjectName,
TopicViewMBean.class, true);

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message