You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Kalpana Jalawadi <ka...@gmail.com> on 2010/04/30 08:57:08 UTC

AdvisoryConsumer

Hi,

I'm using AdvisoryConsumer in my MessageProducer to listen to the consumers
activities. On a consumer shutdown, I would want to perform some cleanup
job. Below is the code:

        Topic advisoryTopic = AdvisorySupport
                .getConsumerAdvisoryTopic((ActiveMQDestination)
JMSConnection.getInstance().getTopic());
        MessageConsumer advisoryConsumer =
JMSConnection.getInstance().getSession().createConsumer(advisoryTopic);
        advisoryConsumer.setMessageListener(new MessageListener() {
            public void onMessage(Message message) {
                if (message instanceof ActiveMQMessage) {
                    ActiveMQMessage aMsg = (ActiveMQMessage) message;
                     
                    DataStructure dataStructure = aMsg.getDataStructure();
                    if (dataStructure instanceof ConsumerInfo) {
                        System.out.println("Consumer started, ConsumerInfo
:" + message.toString());
                        ...
                    } else if (dataStructure instanceof RemoveInfo) {
                        RemoveInfo removeInfo = (RemoveInfo) dataStructure;
                        DataStructure objectId = removeInfo.getObjectId();
                        System.out.println("Consumer stopped, ConsumerInfo
:" + message.toString());
                        // do some clean up
                    } 
                }
            }
        });

RemoveInfo command, exposes the consumerId (some magic string consisting of
connection id, session id and some long value), is there a way to find the
subscription name that is specified while creating the consumer using the
consumer id that is available to me? Or any other work around where I could
clearly identify who is the consumer who is dead?
Any help w.r.t this would be highly appreciated.

Thanks!
-- 
View this message in context: http://old.nabble.com/AdvisoryConsumer-tp28409087p28409087.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: AdvisoryConsumer

Posted by Kalpana Jalawadi <ka...@gmail.com>.
Hi,

Yeah, that would be the easiest solution. In my case, the producer and
consumers are entirely different java processes and all of them can start
and stop randomly. The solution suggested by you could be achieved through
database also, but just wanted to avoid making any database schema changes
just for this purpose.

Thanks,
Kalpana


Dejan Bosanac wrote:
> 
> Hi,
> 
> you can save that info in your application and map consumerid with other
> info from ConsumerInfo when it is connected.
> 
> Cheers
> --
> Dejan Bosanac - http://twitter.com/dejanb
> 
> Open Source Integration - http://fusesource.com/
> ActiveMQ in Action - http://www.manning.com/snyder/
> Blog - http://www.nighttale.net
> 
> 
> On Fri, Apr 30, 2010 at 8:57 AM, Kalpana Jalawadi <
> kalpana.jalawadi@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> I'm using AdvisoryConsumer in my MessageProducer to listen to the
>> consumers
>> activities. On a consumer shutdown, I would want to perform some cleanup
>> job. Below is the code:
>>
>>        Topic advisoryTopic = AdvisorySupport
>>                .getConsumerAdvisoryTopic((ActiveMQDestination)
>> JMSConnection.getInstance().getTopic());
>>        MessageConsumer advisoryConsumer =
>> JMSConnection.getInstance().getSession().createConsumer(advisoryTopic);
>>        advisoryConsumer.setMessageListener(new MessageListener() {
>>            public void onMessage(Message message) {
>>                if (message instanceof ActiveMQMessage) {
>>                    ActiveMQMessage aMsg = (ActiveMQMessage) message;
>>
>>                    DataStructure dataStructure = aMsg.getDataStructure();
>>                    if (dataStructure instanceof ConsumerInfo) {
>>                        System.out.println("Consumer started, ConsumerInfo
>> :" + message.toString());
>>                        ...
>>                    } else if (dataStructure instanceof RemoveInfo) {
>>                        RemoveInfo removeInfo = (RemoveInfo)
>> dataStructure;
>>                        DataStructure objectId = removeInfo.getObjectId();
>>                        System.out.println("Consumer stopped, ConsumerInfo
>> :" + message.toString());
>>                        // do some clean up
>>                    }
>>                }
>>            }
>>        });
>>
>> RemoveInfo command, exposes the consumerId (some magic string consisting
>> of
>> connection id, session id and some long value), is there a way to find
>> the
>> subscription name that is specified while creating the consumer using the
>> consumer id that is available to me? Or any other work around where I
>> could
>> clearly identify who is the consumer who is dead?
>> Any help w.r.t this would be highly appreciated.
>>
>> Thanks!
>> --
>> View this message in context:
>> http://old.nabble.com/AdvisoryConsumer-tp28409087p28409087.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -----
> Dejan Bosanac
> 
> Open Source Integration - http://fusesource.com/
> ActiveMQ in Action - http://www.manning.com/snyder/
> Blog - http://www.nighttale.net
> 

-- 
View this message in context: http://old.nabble.com/AdvisoryConsumer-tp28409087p28409312.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: AdvisoryConsumer

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi,

you can save that info in your application and map consumerid with other
info from ConsumerInfo when it is connected.

Cheers
--
Dejan Bosanac - http://twitter.com/dejanb

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net


On Fri, Apr 30, 2010 at 8:57 AM, Kalpana Jalawadi <
kalpana.jalawadi@gmail.com> wrote:

>
> Hi,
>
> I'm using AdvisoryConsumer in my MessageProducer to listen to the consumers
> activities. On a consumer shutdown, I would want to perform some cleanup
> job. Below is the code:
>
>        Topic advisoryTopic = AdvisorySupport
>                .getConsumerAdvisoryTopic((ActiveMQDestination)
> JMSConnection.getInstance().getTopic());
>        MessageConsumer advisoryConsumer =
> JMSConnection.getInstance().getSession().createConsumer(advisoryTopic);
>        advisoryConsumer.setMessageListener(new MessageListener() {
>            public void onMessage(Message message) {
>                if (message instanceof ActiveMQMessage) {
>                    ActiveMQMessage aMsg = (ActiveMQMessage) message;
>
>                    DataStructure dataStructure = aMsg.getDataStructure();
>                    if (dataStructure instanceof ConsumerInfo) {
>                        System.out.println("Consumer started, ConsumerInfo
> :" + message.toString());
>                        ...
>                    } else if (dataStructure instanceof RemoveInfo) {
>                        RemoveInfo removeInfo = (RemoveInfo) dataStructure;
>                        DataStructure objectId = removeInfo.getObjectId();
>                        System.out.println("Consumer stopped, ConsumerInfo
> :" + message.toString());
>                        // do some clean up
>                    }
>                }
>            }
>        });
>
> RemoveInfo command, exposes the consumerId (some magic string consisting of
> connection id, session id and some long value), is there a way to find the
> subscription name that is specified while creating the consumer using the
> consumer id that is available to me? Or any other work around where I could
> clearly identify who is the consumer who is dead?
> Any help w.r.t this would be highly appreciated.
>
> Thanks!
> --
> View this message in context:
> http://old.nabble.com/AdvisoryConsumer-tp28409087p28409087.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>