You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Tim Chen <ti...@evri.com> on 2010/11/18 23:10:57 UTC

JMS Client reconnect

Hi all,

I wonder what's the best way to handle reconnect to the broker when broker
is unavailable (network is down / broker crashed, etc) using Java JMS client
to C++ broker?

Currently when using the JMS client when the broker is killed, a runtime
exception ( ConnectionException ) is thrown internally in qpid and I don't
see a way I can get this exception.

I tried to add a check each time it sends a message if the broker connection
is closed ( AMQConnection.isClosed() ) to re-attempt to reconnect.

However, I see that if the broker is disconnected not via
AMQConnection.close(), the state is never set to CLOSED and still set as
OPEN.

>From reading this:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf

It has reconnect flags on using Python and C++ clients to automatically
reconnect if connection is lost.

But I wonder what's the best way to do this in JMS client?

Thanks,

Tim

Re: JMS Client reconnect

Posted by Tim Chen <ti...@evri.com>.
I'm currently running a cluster, and I do see it is automatically failing
over to other nodes in the cluster.

But I am trying to test the case where all brokers in the cluster is down (
or in other words the cluster is down ),

I'm hoping both the producer and the client won't just die but keep on
attempting to reconnect until the cluster is backup, so I'm trying to

get the exception from the Javax.jms.connection so I can start the retry
logic.

You mentioned a connection listener, are you referring to ExceptionListener?


http://download.oracle.com/javaee/1.4/api/javax/jms/ExceptionListener.html

And also I wonder if there is any best practices for reconnecting when there
are multiple producers in different threads all sharing one connection but
multiple sessions?

Tim

On Mon, Nov 22, 2010 at 7:46 AM, Rajith Attapattu <ra...@gmail.com>wrote:

> On Thu, Nov 18, 2010 at 5:10 PM, Tim Chen <ti...@evri.com> wrote:
>
> > Hi all,
> >
> > I wonder what's the best way to handle reconnect to the broker when
> broker
> > is unavailable (network is down / broker crashed, etc) using Java JMS
> > client
> > to C++ broker?
> >
>
> Are you running a cluster or is it a bunch of standalone brokers ?
>
>
>
> > Currently when using the JMS client when the broker is killed, a runtime
> > exception ( ConnectionException ) is thrown internally in qpid and I
> don't
> > see a way I can get this exception.
> >
> >
> The Qpid JMS client supports transparent failover if configured properly.
>
> If you are running a cluster then
> -------------------------------------------
> For c++ broker you can set the failover method to "failover_exchange" and
> the client will transparently retrieve the available brokers from the
> cluster and will connect to one of them if the current broker fails.
> Ex amqp://guest:guest@clientid
> /testpath?brokerlist='tcp://localhost:5672'&failover='failover_exchange'
>
> If you are running a set of standalone brokers
> -------------------------------------------------------
> You can set the failover method to round robin an provide a list of
> brokers.
> Ex amqp://guest:guest@clientid
>
> /testpath?brokerlist='tcp://host1:5672;tcp://host2:5672..;tcp://hostn:5672'&failover='roundrobin'
>
>
> Also if all attempts are unsuccessful (i.e total cluster failure or all
> brokers in the list are down) then it will throw an exception if there is a
> connection listener set.
> It will not notify a connection exception If and only if it can connect to
> another broker in the cluster (or the list of brokers if provided with
> failover=roundrobin).
> i.e it will not notify any intermediate failures.
>
>
>
>
> > I tried to add a check each time it sends a message if the broker
> > connection
> > is closed ( AMQConnection.isClosed() ) to re-attempt to reconnect.
> >
> > However, I see that if the broker is disconnected not via
> > AMQConnection.close(), the state is never set to CLOSED and still set as
> > OPEN.
> >
>
> Please stick to the standard JMS interfaces as internal classes like
> AMQConnection are subject change from release to release.
>
>
> >
> > From reading this:
> >
> >
> http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf
> >
> > It has reconnect flags on using Python and C++ clients to automatically
> > reconnect if connection is lost.
> >
> > But I wonder what's the best way to do this in JMS client?
> >
> > Thanks,
> >
> > Tim
> >
>
>
>
> --
> Regards,
>
> Rajith Attapattu
> Red Hat
> http://rajith.2rlabs.com/
>

Re: JMS Client reconnect

Posted by Rajith Attapattu <ra...@gmail.com>.
On Thu, Nov 18, 2010 at 5:10 PM, Tim Chen <ti...@evri.com> wrote:

> Hi all,
>
> I wonder what's the best way to handle reconnect to the broker when broker
> is unavailable (network is down / broker crashed, etc) using Java JMS
> client
> to C++ broker?
>

Are you running a cluster or is it a bunch of standalone brokers ?



> Currently when using the JMS client when the broker is killed, a runtime
> exception ( ConnectionException ) is thrown internally in qpid and I don't
> see a way I can get this exception.
>
>
The Qpid JMS client supports transparent failover if configured properly.

If you are running a cluster then
-------------------------------------------
For c++ broker you can set the failover method to "failover_exchange" and
the client will transparently retrieve the available brokers from the
cluster and will connect to one of them if the current broker fails.
Ex amqp://guest:guest@clientid
/testpath?brokerlist='tcp://localhost:5672'&failover='failover_exchange'

If you are running a set of standalone brokers
-------------------------------------------------------
You can set the failover method to round robin an provide a list of brokers.
Ex amqp://guest:guest@clientid
/testpath?brokerlist='tcp://host1:5672;tcp://host2:5672..;tcp://hostn:5672'&failover='roundrobin'


Also if all attempts are unsuccessful (i.e total cluster failure or all
brokers in the list are down) then it will throw an exception if there is a
connection listener set.
It will not notify a connection exception If and only if it can connect to
another broker in the cluster (or the list of brokers if provided with
failover=roundrobin).
i.e it will not notify any intermediate failures.




> I tried to add a check each time it sends a message if the broker
> connection
> is closed ( AMQConnection.isClosed() ) to re-attempt to reconnect.
>
> However, I see that if the broker is disconnected not via
> AMQConnection.close(), the state is never set to CLOSED and still set as
> OPEN.
>

Please stick to the standard JMS interfaces as internal classes like
AMQConnection are subject change from release to release.


>
> From reading this:
>
> http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf
>
> It has reconnect flags on using Python and C++ clients to automatically
> reconnect if connection is lost.
>
> But I wonder what's the best way to do this in JMS client?
>
> Thanks,
>
> Tim
>



-- 
Regards,

Rajith Attapattu
Red Hat
http://rajith.2rlabs.com/

Re: JMS Client reconnect

Posted by Marnie McCormack <ma...@googlemail.com>.
Hi Tim,

The Java client uses the connection URL to control failover, but I'm not
sure whether/how that is honoured by the C++ broker. It also defaults on
trunk to use a NoFailover policy.

Rajith - I think you might have the most up-to-date knowledge on the Java
client failover on trunk, do you have a moment to assist Tim ?

Regards,
Marnie

On Sun, Nov 21, 2010 at 8:30 PM, Tim Chen <ti...@evri.com> wrote:

> Anyone?
>
> Tim
>
> On Thu, Nov 18, 2010 at 2:10 PM, Tim Chen <ti...@evri.com> wrote:
>
> > Hi all,
> >
> > I wonder what's the best way to handle reconnect to the broker when
> broker
> > is unavailable (network is down / broker crashed, etc) using Java JMS
> client
> > to C++ broker?
> >
> > Currently when using the JMS client when the broker is killed, a runtime
> > exception ( ConnectionException ) is thrown internally in qpid and I
> don't
> > see a way I can get this exception.
> >
> > I tried to add a check each time it sends a message if the broker
> > connection is closed ( AMQConnection.isClosed() ) to re-attempt to
> > reconnect.
> >
> > However, I see that if the broker is disconnected not via
> > AMQConnection.close(), the state is never set to CLOSED and still set as
> > OPEN.
> >
> > From reading this:
> >
> >
> http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf
> >
> > It has reconnect flags on using Python and C++ clients to automatically
> > reconnect if connection is lost.
> >
> > But I wonder what's the best way to do this in JMS client?
> >
> > Thanks,
> >
> > Tim
> >
>

Re: JMS Client reconnect

Posted by Carl Trieloff <cc...@redhat.com>.

Is the failover for a cluster or just to brokers.

For a cluster, the heartbeat etc need to be setup and the rest is automatic
from the failover exchange.

If just two brokers, then the connection URL needs to be used.

Carl.


On 11/21/2010 03:30 PM, Tim Chen wrote:
> Anyone?
>
> Tim
>
> On Thu, Nov 18, 2010 at 2:10 PM, Tim Chen<ti...@evri.com>  wrote:
>
>    
>> Hi all,
>>
>> I wonder what's the best way to handle reconnect to the broker when broker
>> is unavailable (network is down / broker crashed, etc) using Java JMS client
>> to C++ broker?
>>
>> Currently when using the JMS client when the broker is killed, a runtime
>> exception ( ConnectionException ) is thrown internally in qpid and I don't
>> see a way I can get this exception.
>>
>> I tried to add a check each time it sends a message if the broker
>> connection is closed ( AMQConnection.isClosed() ) to re-attempt to
>> reconnect.
>>
>> However, I see that if the broker is disconnected not via
>> AMQConnection.close(), the state is never set to CLOSED and still set as
>> OPEN.
>>
>>  From reading this:
>>
>> http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf
>>
>> It has reconnect flags on using Python and C++ clients to automatically
>> reconnect if connection is lost.
>>
>> But I wonder what's the best way to do this in JMS client?
>>
>> Thanks,
>>
>> Tim
>>
>>      
>    


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


Re: JMS Client reconnect

Posted by Tim Chen <ti...@evri.com>.
Anyone?

Tim

On Thu, Nov 18, 2010 at 2:10 PM, Tim Chen <ti...@evri.com> wrote:

> Hi all,
>
> I wonder what's the best way to handle reconnect to the broker when broker
> is unavailable (network is down / broker crashed, etc) using Java JMS client
> to C++ broker?
>
> Currently when using the JMS client when the broker is killed, a runtime
> exception ( ConnectionException ) is thrown internally in qpid and I don't
> see a way I can get this exception.
>
> I tried to add a check each time it sends a message if the broker
> connection is closed ( AMQConnection.isClosed() ) to re-attempt to
> reconnect.
>
> However, I see that if the broker is disconnected not via
> AMQConnection.close(), the state is never set to CLOSED and still set as
> OPEN.
>
> From reading this:
>
> http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.3/pdf/Programming_in_Apache_Qpid/Red_Hat_Enterprise_MRG-1.3-Programming_in_Apache_Qpid-en-US.pdf
>
> It has reconnect flags on using Python and C++ clients to automatically
> reconnect if connection is lost.
>
> But I wonder what's the best way to do this in JMS client?
>
> Thanks,
>
> Tim
>