You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Patrick Ruckstuhl <pa...@tario.org> on 2009/01/19 07:42:23 UTC

Real world example for CMS?

Hi,

does someone have a real world example for using CMS?

My situation is the following.

I have an application that has multiple threads and sends and receives
messages. ActiveMQ itself is running on a different host so it is possible
(and happens form time to time) that the network connection is lost and
therefore we need to handle this situation.

I found a SessionPool in the cmsutil package, is this the recommended way to
deal with it (have a SessionPool and each threads gets a session from
there). What's needed to set it up? Does it deal with lost connections or if
not how else can I deal with it?

Thanks and Regards,
Patrick
-- 
View this message in context: http://www.nabble.com/Real-world-example-for-CMS--tp21537664p21537664.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Real world example for CMS?

Posted by Timothy Bish <ta...@gmail.com>.
On Mon, 2009-01-19 at 13:58 -0800, Patrick Ruckstuhl wrote:
> Hi Timothy
> 
> I'm now able to deal with connection interruptions on the sending side but
> seem to get some problems on the receiving side (there are some partner that
> simple just receive messages)
> 
> What I currently do is (in pseudocode)
> 
> Consumer c = session.createConsumer(SomeDestination)
> 
> while(true) {
>     Message m = c.receiveTimeout(1Second)
>     if(m != Void){
>        doSomething()
>     }
> }
> 
> 
> Now my problem seems to be that, "c.receive" doesn't throw an exception if
> the connection is lost and therefore I'm not able to detect the lost
> connection. 
> 

Are you registering am Exception Listener on the Connection ?  
Also depending on the platform the TCP stack my not fail immediately but
wait for some timeout, so you may need to play around with the TCP settings.


-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/




Re: Real world example for CMS?

Posted by Patrick Ruckstuhl <pa...@tario.org>.
Hi Timothy

I'm now able to deal with connection interruptions on the sending side but
seem to get some problems on the receiving side (there are some partner that
simple just receive messages)

What I currently do is (in pseudocode)

Consumer c = session.createConsumer(SomeDestination)

while(true) {
    Message m = c.receiveTimeout(1Second)
    if(m != Void){
       doSomething()
    }
}


Now my problem seems to be that, "c.receive" doesn't throw an exception if
the connection is lost and therefore I'm not able to detect the lost
connection. 


Thanks again for your helpful advice

Patrick



Timothy Bish wrote:
> 
> 
>> Now to the second part of my question:
>> What is the recommended way to deal with multiple threads? Should I use
>> the
>> SessionPool? Or should I share one session and protect it? Any hints how
>> to
>> best deal with recreating the resources?
> 
> We've made every attempt to make the classes in CMS thread safe, so you
> could share one session amongst many threads.  Probably the best thing
> todo is hide the actual CMS code behind some sort of Proxy object that
> you give to each of your threads that provides the functionality that
> they need to send their messages, then in the proxy you could monitor
> the Connection for exceptions using an exception listener and destroy
> and recreate all the resources that you did initially while locking
> something like a mutex that prevents your producers from publishing
> anything while you are reconnecting.  
> 
> Once 3.0 is done all of that should become transparent to the user if
> they use the Failover Transport.  But until then you could do something
> like I described to make it work for now.  
> 
> SessionPool is really only intended for use in the CMSTemplate code, not
> in your own code.
> 
> Regards
> Tim.
> 
> 
> 
> -- 
> Tim Bish
> http://fusesource.com
> http://timbish.blogspot.com/
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Real-world-example-for-CMS--tp21537664p21552500.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Real world example for CMS?

Posted by Timothy Bish <ta...@gmail.com>.
> Now to the second part of my question:
> What is the recommended way to deal with multiple threads? Should I use the
> SessionPool? Or should I share one session and protect it? Any hints how to
> best deal with recreating the resources?

We've made every attempt to make the classes in CMS thread safe, so you
could share one session amongst many threads.  Probably the best thing
todo is hide the actual CMS code behind some sort of Proxy object that
you give to each of your threads that provides the functionality that
they need to send their messages, then in the proxy you could monitor
the Connection for exceptions using an exception listener and destroy
and recreate all the resources that you did initially while locking
something like a mutex that prevents your producers from publishing
anything while you are reconnecting.  

Once 3.0 is done all of that should become transparent to the user if
they use the Failover Transport.  But until then you could do something
like I described to make it work for now.  

SessionPool is really only intended for use in the CMSTemplate code, not
in your own code.

Regards
Tim.



-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/




Re: Real world example for CMS?

Posted by Patrick Ruckstuhl <pa...@tario.org>.
Ok, thanks for the information regarding failover. I'll be definitely looking
forward to Release 3.0.

Now to the second part of my question:
What is the recommended way to deal with multiple threads? Should I use the
SessionPool? Or should I share one session and protect it? Any hints how to
best deal with recreating the resources?


Thanks and Regards,
Patrick


Timothy Bish wrote:
> 
> Currently the only way to detect and recover from a broker disconnect is
> to set an Exception Listener on the Connection and when it fires you
> should recreate the resources you were using.  
> 
> We are currently working on V3.0 of ActiveMQ-CPP which will include
> failover support but until then the recovery process is a manual one
> that the user must implement.
> 
> Regards
> Tim.
> 
> On Sun, 2009-01-18 at 22:42 -0800, Patrick Ruckstuhl wrote:
>> Hi,
>> 
>> does someone have a real world example for using CMS?
>> 
>> My situation is the following.
>> 
>> I have an application that has multiple threads and sends and receives
>> messages. ActiveMQ itself is running on a different host so it is
>> possible
>> (and happens form time to time) that the network connection is lost and
>> therefore we need to handle this situation.
>> 
>> I found a SessionPool in the cmsutil package, is this the recommended way
>> to
>> deal with it (have a SessionPool and each threads gets a session from
>> there). What's needed to set it up? Does it deal with lost connections or
>> if
>> not how else can I deal with it?
>> 
>> Thanks and Regards,
>> Patrick
> -- 
> Tim Bish
> http://fusesource.com
> http://timbish.blogspot.com/
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Real-world-example-for-CMS--tp21537664p21546359.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Real world example for CMS?

Posted by Timothy Bish <ta...@gmail.com>.
Currently the only way to detect and recover from a broker disconnect is
to set an Exception Listener on the Connection and when it fires you
should recreate the resources you were using.  

We are currently working on V3.0 of ActiveMQ-CPP which will include
failover support but until then the recovery process is a manual one
that the user must implement.

Regards
Tim.

On Sun, 2009-01-18 at 22:42 -0800, Patrick Ruckstuhl wrote:
> Hi,
> 
> does someone have a real world example for using CMS?
> 
> My situation is the following.
> 
> I have an application that has multiple threads and sends and receives
> messages. ActiveMQ itself is running on a different host so it is possible
> (and happens form time to time) that the network connection is lost and
> therefore we need to handle this situation.
> 
> I found a SessionPool in the cmsutil package, is this the recommended way to
> deal with it (have a SessionPool and each threads gets a session from
> there). What's needed to set it up? Does it deal with lost connections or if
> not how else can I deal with it?
> 
> Thanks and Regards,
> Patrick
-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/