You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by beaker <be...@freenet.de> on 2008/05/08 16:25:55 UTC

Detect consumers?

Hello,

is it possible for a producer to detect, if there are any consumers on the
topic/queue he is sending?

I want the producer to only send out messages, if there is someone listening
for them.

Bye,
beaker
-- 
View this message in context: http://www.nabble.com/Detect-consumers--tp17126905s2354p17126905.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Detect consumers?

Posted by beaker <be...@freenet.de>.
Here is my file. I basically took some examples from the example server
mentioned above ... a have one client connected to it that sends messages
and another client that receives them. 

Then I out the third one just for teseting purposes, that should tell me if
there are any consumers. But there's nothing coming in.

Cheers, beaker




rajdavies wrote:
> 
> Can you post your entire code - preferably as a junit test case  
> attached to a jira ?
> 
> 
> cheers,
> 
> Rob
> 
> http://open.iona.com/products/enterprise-activemq
> http://rajdavies.blogspot.com/
> 
> 
> On 19 May 2008, at 07:22, beaker wrote:
> 
>>
>> Hello,
>>
>> I tried the Advisory Topics, but somehow I can not manage to get any
>> advisory messages...
>>
>> I have tested this with a small test server I have found here:
>> http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/
>>
>> This is a piece of code where I tried to set up a consumer for the  
>> advisory
>> messages:
>>
>>            ActiveMQDestination topic = (ActiveMQDestination)
>> context.lookup("ChatTopic");
>>
>>            Destination advisoryDestination =
>> AdvisorySupport.getConsumerAdvisoryTopic(topic);
>>
>>            MessageConsumer consumer =
>> session.createConsumer(advisoryDestination);
>>
>> Then I tried to connect some consumers to the topic "ChatTopic", but  
>> I never
>> get an advisory message. Can you tell me what is wrong? Is there  
>> maybe some
>> kind of example or tutorial on how to do this?
>>
>> Cheers,
>> beaker
>>
>>
>> James.Strachan wrote:
>>>
>>> 2008/5/8 beaker <be...@freenet.de>:
>>>>
>>>> Hello,
>>>>
>>>> is it possible for a producer to detect, if there are any  
>>>> consumers on
>>>> the
>>>> topic/queue he is sending?
>>>
>>> Yes - you can use advisories...
>>> http://activemq.apache.org/advisory-message.html
>>>
>>> e.g. try using the ConsumerEventSource helper class...
>>> http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/advisory/ConsumerEventSource.html
>>>
>>>> I want the producer to only send out messages, if there is someone
>>>> listening
>>>> for them.
>>>
>>> We could maybe enhance the JMS client so that it can avoid sending
>>> messages to topics which have no consumers (i.e. to reduce the cost  
>>> of
>>> marshalling the message on the wire and sending it to the broker and
>>> the broker consuming it).
>>>
>>> -- 
>>> James
>>> -------
>>> http://macstrac.blogspot.com/
>>>
>>> Open Source Integration
>>> http://open.iona.com
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Detect-consumers--tp17126905s2354p17311984.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
> 
> 
> 
> 
> 
> 
> 
> 
http://www.nabble.com/file/p17316562/ConsumerWatcher.java
ConsumerWatcher.java 
-- 
View this message in context: http://www.nabble.com/Detect-consumers--tp17126905s2354p17316562.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Detect consumers?

Posted by Rob Davies <ra...@gmail.com>.
Can you post your entire code - preferably as a junit test case  
attached to a jira ?


cheers,

Rob

http://open.iona.com/products/enterprise-activemq
http://rajdavies.blogspot.com/


On 19 May 2008, at 07:22, beaker wrote:

>
> Hello,
>
> I tried the Advisory Topics, but somehow I can not manage to get any
> advisory messages...
>
> I have tested this with a small test server I have found here:
> http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/
>
> This is a piece of code where I tried to set up a consumer for the  
> advisory
> messages:
>
>            ActiveMQDestination topic = (ActiveMQDestination)
> context.lookup("ChatTopic");
>
>            Destination advisoryDestination =
> AdvisorySupport.getConsumerAdvisoryTopic(topic);
>
>            MessageConsumer consumer =
> session.createConsumer(advisoryDestination);
>
> Then I tried to connect some consumers to the topic "ChatTopic", but  
> I never
> get an advisory message. Can you tell me what is wrong? Is there  
> maybe some
> kind of example or tutorial on how to do this?
>
> Cheers,
> beaker
>
>
> James.Strachan wrote:
>>
>> 2008/5/8 beaker <be...@freenet.de>:
>>>
>>> Hello,
>>>
>>> is it possible for a producer to detect, if there are any  
>>> consumers on
>>> the
>>> topic/queue he is sending?
>>
>> Yes - you can use advisories...
>> http://activemq.apache.org/advisory-message.html
>>
>> e.g. try using the ConsumerEventSource helper class...
>> http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/advisory/ConsumerEventSource.html
>>
>>> I want the producer to only send out messages, if there is someone
>>> listening
>>> for them.
>>
>> We could maybe enhance the JMS client so that it can avoid sending
>> messages to topics which have no consumers (i.e. to reduce the cost  
>> of
>> marshalling the message on the wire and sending it to the broker and
>> the broker consuming it).
>>
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://open.iona.com
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Detect-consumers--tp17126905s2354p17311984.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>







Re: Detect consumers?

Posted by beaker <be...@freenet.de>.
Hello,

I tried the Advisory Topics, but somehow I can not manage to get any
advisory messages...

I have tested this with a small test server I have found here:
http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/

This is a piece of code where I tried to set up a consumer for the advisory
messages:

            ActiveMQDestination topic = (ActiveMQDestination)
context.lookup("ChatTopic");

            Destination advisoryDestination =
AdvisorySupport.getConsumerAdvisoryTopic(topic);

            MessageConsumer consumer =
session.createConsumer(advisoryDestination);

Then I tried to connect some consumers to the topic "ChatTopic", but I never
get an advisory message. Can you tell me what is wrong? Is there maybe some
kind of example or tutorial on how to do this?

Cheers,
beaker


James.Strachan wrote:
> 
> 2008/5/8 beaker <be...@freenet.de>:
>>
>>  Hello,
>>
>>  is it possible for a producer to detect, if there are any consumers on
>> the
>>  topic/queue he is sending?
> 
> Yes - you can use advisories...
> http://activemq.apache.org/advisory-message.html
> 
> e.g. try using the ConsumerEventSource helper class...
> http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/advisory/ConsumerEventSource.html
> 
>>  I want the producer to only send out messages, if there is someone
>> listening
>>  for them.
> 
> We could maybe enhance the JMS client so that it can avoid sending
> messages to topics which have no consumers (i.e. to reduce the cost of
> marshalling the message on the wire and sending it to the broker and
> the broker consuming it).
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Detect-consumers--tp17126905s2354p17311984.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Detect consumers?

Posted by James Strachan <ja...@gmail.com>.
2008/5/8 beaker <be...@freenet.de>:
>
>  Hello,
>
>  is it possible for a producer to detect, if there are any consumers on the
>  topic/queue he is sending?

Yes - you can use advisories...
http://activemq.apache.org/advisory-message.html

e.g. try using the ConsumerEventSource helper class...
http://activemq.apache.org/maven/activemq-core/apidocs/org/apache/activemq/advisory/ConsumerEventSource.html

>  I want the producer to only send out messages, if there is someone listening
>  for them.

We could maybe enhance the JMS client so that it can avoid sending
messages to topics which have no consumers (i.e. to reduce the cost of
marshalling the message on the wire and sending it to the broker and
the broker consuming it).

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com