activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Snyder <bruce.sny...@gmail.com>
Subject Re: How to publish only if active subscribers?
Date Sun, 29 Nov 2009 00:39:22 GMT
On Sat, Nov 28, 2009 at 2:10 PM, jaguarg <fotshudi@gmail.com> wrote:
>
> Hi,
>
> I came across this http://activemq.apache.org/advisory-message.html   I
> guess advisory message could be used. any practical example?
>
> Thanks
> --
> jaguarg
>
> jaguarg wrote:
>>
>> Hi,
>> I would like to implement a feature where I only publish on a specific
>> topic if there is one or more subscribers listening on for this topic?
>> This is my sample code:
>>  ActiveMQConnectionFactory factory = new
>> ActiveMQConnectionFactory("tcp://<MY ACTIVEMQ HOST>:61616");
>>         connection = factory.createConnection();
>>         session = connection.createSession(false,
>> Session.AUTO_ACKNOWLEDGE);
>> ...
>>
>>  Topic topic = session.createTopic(<MY TOPIC>);
>>    MessageProducer publisher = session.createProducer(topic);
>>             publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>>             publisher.send(session.createTextMessage(<MY DATA>);
>>
>> How do I avoid pushing this data if there are not subscriber?

First you must understand the premise of message-oriented middleware
(MOM). The whole point of a MOM is to facilitate the asynchronous send
and receive of messages. That is, the sender has no knowledge of the
receiver and vice versa. I.e., there is no requirement that there be
an active subscription on a destination before publishing.

To answer your questions, there is no functionality or logic built in
to ActiveMQ that will provide what you describe. That doesn't mean
that you couldn't build it yourself. However, If you truly want this
functionality, then I believe that you probably should not be using
JMS. Instead you should consider some RPC-based technology that
already exists such as Spring Remoting, RMI, CORBA, web services. I
recommend looking at Spring Remoting APIs instead of writing your such
services from scratch as it will dramatically simplify the task:

http://static.springsource.org/spring/docs/2.5.x/reference/remoting.html

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Mime
View raw message