You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Stefan Oestreicher <oe...@gmail.com> on 2011/11/04 16:37:07 UTC

peer protocol - wait for discovery

Hi,

I'm working on a multi-user Swing application where it would be nice if 
users could be informed about updates made by others in real-time. For 
this application it is pretty much a convenience feature so it's not 
necessary for correct operation.
After looking into ActiveMQ I discovered the Peer protocol which seems 
to be exactly what I need because I don't want to use a central server. 
I made a small test example which seemed to work perfectly.

But one thing I would like to do is send a message on application start 
to announce the client to the others.  Unfortunately I'm not sure how to 
get this to work because if I immediately send a message after starting 
the connection it's only delivered to the embedded broker. Calling 
Thread.sleep for a short time before sending the message makes it work. 
So I guess that's because it takes some time until the discovery is 
finished, but how can I wait for that? I stumbled upon Advisories and it 
sounds like maybe that's what I need but I'm having a hard time finding 
more information about this. I'm quite new to JMS so please forgive my 
ignorance.

I would appreciate any pointers.

You can see the relevant part of the test code I used here, in case it 
makes any difference: http://pastebin.com/NsZmu79m


thanks,
Stefan

Re: peer protocol - wait for discovery

Posted by Stefan Oestreicher <oe...@gmail.com>.
Hi,

> You can do that by simply registering a consumer for
>
> Destination advisoryTopic = AdvisorySupport.getConsumerAdvisoryTopic(dest)
>
> and send a message only after you received a first message there.

Ah, I see, that should be simple enough.  Thank you very much.

best regards
Stefan

Re: peer protocol - wait for discovery

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

the problem is that you send non-persistent messages to the topic and if
there's no consumers on the topic (which there isn't in your case), the
message is being discarded. As you suggested, the solution would be to use
advisory messages to wait for a consumer on your topic, before sending a
message.

You can do that by simply registering a consumer for

Destination advisoryTopic = AdvisorySupport.getConsumerAdvisoryTopic(dest)

and send a message only after you received a first message there.

Regards
-- 
Dejan Bosanac - http://twitter.com/dejanb
-----------------
The experts in open source integration and messaging - http://fusesource.com
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net


On Fri, Nov 4, 2011 at 4:37 PM, Stefan Oestreicher <oe...@gmail.com> wrote:

> Hi,
>
> I'm working on a multi-user Swing application where it would be nice if
> users could be informed about updates made by others in real-time. For this
> application it is pretty much a convenience feature so it's not necessary
> for correct operation.
> After looking into ActiveMQ I discovered the Peer protocol which seems to
> be exactly what I need because I don't want to use a central server. I made
> a small test example which seemed to work perfectly.
>
> But one thing I would like to do is send a message on application start to
> announce the client to the others.  Unfortunately I'm not sure how to get
> this to work because if I immediately send a message after starting the
> connection it's only delivered to the embedded broker. Calling Thread.sleep
> for a short time before sending the message makes it work. So I guess
> that's because it takes some time until the discovery is finished, but how
> can I wait for that? I stumbled upon Advisories and it sounds like maybe
> that's what I need but I'm having a hard time finding more information
> about this. I'm quite new to JMS so please forgive my ignorance.
>
> I would appreciate any pointers.
>
> You can see the relevant part of the test code I used here, in case it
> makes any difference: http://pastebin.com/NsZmu79m
>
>
> thanks,
> Stefan
>