You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by icfantv <ad...@readytalk.com> on 2009/01/16 01:31:40 UTC

Connection creation timeout setting

Hi-

Did a cursory search but didn't find anything related to this so I apologize
in advance if it's been asked and answered - I didn't see it.

Is there a way to set a connection timeout on the connection factory class
such that the thread doesn't block until a connection is successfully made? 
I see several timeout related methods in the connection object but don't see
anything specifically related to connection timeouts.

Thanks in advance,

--adam
-- 
View this message in context: http://www.nabble.com/Connection-creation-timeout-setting-tp21490199p21490199.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Connection creation timeout setting

Posted by Bruce Snyder <br...@gmail.com>.
On Fri, Jan 16, 2009 at 1:46 PM, icfantv <ad...@readytalk.com> wrote:
>
> Bruce-
>
> Yah, I just discovered that and posted a response to myself for posterity.
>
> Let me make sure I understand the failover transport correctly: It will, by
> default, attempt to reconnect every 30 seconds indefinitely until an
> ActiveMQ server is running on the default URL (assuming no additional
> failover urls)?

Correct - and it's configurable.

> And to answer your question, at first, I thought I didn't want the
> connection thread to block, period.  But the more I think about it, if my
> above understanding of the failover transport is correct, I think I like
> that functionality better because it keeps me from having to handle
> connection failures - at least on the code side of things.

Bingo!

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

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/

Blog: http://bruceblog.org/

Re: Connection creation timeout setting

Posted by icfantv <ad...@readytalk.com>.
Bruce-

Yah, I just discovered that and posted a response to myself for posterity.

Let me make sure I understand the failover transport correctly: It will, by
default, attempt to reconnect every 30 seconds indefinitely until an
ActiveMQ server is running on the default URL (assuming no additional
failover urls)?

And to answer your question, at first, I thought I didn't want the
connection thread to block, period.  But the more I think about it, if my
above understanding of the failover transport is correct, I think I like
that functionality better because it keeps me from having to handle
connection failures - at least on the code side of things.

--adam


bsnyder wrote:
> 
> On Fri, Jan 16, 2009 at 8:27 AM, icfantv <ad...@readytalk.com>
> wrote:
> 
> Just to make sure I understand what you're asking, you don't want the
> client thread that's trying to connect to the broker to block until a
> connection is completed, correct? You must be using the failover
> transport to connect because it will block and wait for the connection
> to be made based on its configuration:
> 
> http://activemq.apache.org/failover-transport-reference.html
> 
> If you use the straight TCP transport without the failover transport
> the call will not block and wait:
> 
> http://activemq.apache.org/tcp-transport-reference.html
> 
> As far as connecting to the broker in an asynchronous manner when
> using the failover transport, such functionality does not exist
> currently.
> 
> Bruce
> 

-- 
View this message in context: http://www.nabble.com/Connection-creation-timeout-setting-tp21490199p21508121.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Connection creation timeout setting

Posted by Bruce Snyder <br...@gmail.com>.
On Fri, Jan 16, 2009 at 8:27 AM, icfantv <ad...@readytalk.com> wrote:
>
> I'm trying to create a connection such that it will time out if the ActiveMQ
> server isn't running rather than blocking indefinitely.  If I do it in a
> background thread and it never connects, but rather, blocks indefinitely,
> Java provides no way to terminate the thread.
>
> Not to harp on the developers, but this seems like a serious design flaw
> especially since underneath it's probably using the Java network stack which
> supports connection time outs.
>
> If anyone has any other ideas, I'm open to suggestions or I'm going to be
> forced to delve into the code and perhaps implement some type of time out
> mechanism on the connection.

Just to make sure I understand what you're asking, you don't want the
client thread that's trying to connect to the broker to block until a
connection is completed, correct? You must be using the failover
transport to connect because it will block and wait for the connection
to be made based on its configuration:

http://activemq.apache.org/failover-transport-reference.html

If you use the straight TCP transport without the failover transport
the call will not block and wait:

http://activemq.apache.org/tcp-transport-reference.html

As far as connecting to the broker in an asynchronous manner when
using the failover transport, such functionality does not exist
currently.

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

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/

Blog: http://bruceblog.org/

Re: Connection creation timeout setting

Posted by icfantv <ad...@readytalk.com>.
I'm trying to create a connection such that it will time out if the ActiveMQ
server isn't running rather than blocking indefinitely.  If I do it in a
background thread and it never connects, but rather, blocks indefinitely,
Java provides no way to terminate the thread.

Not to harp on the developers, but this seems like a serious design flaw
especially since underneath it's probably using the Java network stack which
supports connection time outs.

If anyone has any other ideas, I'm open to suggestions or I'm going to be
forced to delve into the code and perhaps implement some type of time out
mechanism on the connection.

--adam


bsnyder wrote:
> 
> On Thu, Jan 15, 2009 at 5:31 PM, icfantv <ad...@readytalk.com>
> wrote:
>>
>> Hi-
>>
>> Did a cursory search but didn't find anything related to this so I
>> apologize
>> in advance if it's been asked and answered - I didn't see it.
>>
>> Is there a way to set a connection timeout on the connection factory
>> class
>> such that the thread doesn't block until a connection is successfully
>> made?
>> I see several timeout related methods in the connection object but don't
>> see
>> anything specifically related to connection timeouts.
> 
> There are no such timeouts on the ActiveMQConnection. What is it that
> you're trying to achieve exactly?
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*");'
> 

-- 
View this message in context: http://www.nabble.com/Connection-creation-timeout-setting-tp21490199p21501819.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Connection creation timeout setting

Posted by Bruce Snyder <br...@gmail.com>.
On Thu, Jan 15, 2009 at 5:31 PM, icfantv <ad...@readytalk.com> wrote:
>
> Hi-
>
> Did a cursory search but didn't find anything related to this so I apologize
> in advance if it's been asked and answered - I didn't see it.
>
> Is there a way to set a connection timeout on the connection factory class
> such that the thread doesn't block until a connection is successfully made?
> I see several timeout related methods in the connection object but don't see
> anything specifically related to connection timeouts.

There are no such timeouts on the ActiveMQConnection. What is it that
you're trying to achieve exactly?

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

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/

Blog: http://bruceblog.org/

Re: Connection creation timeout setting

Posted by Bruce Snyder <br...@gmail.com>.
On Fri, Jan 16, 2009 at 1:14 PM, icfantv <ad...@readytalk.com> wrote:
>
> So, "technically" timeouts are supported for TCP Transports.  Here are the
> URI configuration parameters:
> http://activemq.apache.org/tcp-transport-reference.html
> http://activemq.apache.org/tcp-transport-reference.html

Yes, the connectionTimeout is used when connecting to a socket via TCP
(maybe this would work for you?) and the soTimeout is used to timeout
reads on a socket.

> And, if one uses the standard TCP URL of tcp://localhost:61616 and ActiveMQ
> is not running, one (correctly and immediately) gets a JMSException (caused
> by a ConnectionException) with the reason being that the connection is
> refused.

Correct.

> However, in debugging, I noticed that if one uses the DEFAULT connection
> URL, these parameters are ignored and the default TCP URL of
> tcp://localhost:61616 is actually failover://tcp://localhost:61616.

Correct.

> It's not obvious to me yet what the significance of the failover protocol
> actually means, but I'm still digging.

The failover transport adds reconnect features on top of the other
transports so that if the connection to a broker fails, the failover
transport automatically reconnects to another URI in the list. This
can be used with just a single URI as well.

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

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/

Blog: http://bruceblog.org/

Re: Connection creation timeout setting

Posted by icfantv <ad...@readytalk.com>.
So, "technically" timeouts are supported for TCP Transports.  Here are the
URI configuration parameters:  
http://activemq.apache.org/tcp-transport-reference.html
http://activemq.apache.org/tcp-transport-reference.html 

And, if one uses the standard TCP URL of tcp://localhost:61616 and ActiveMQ
is not running, one (correctly and immediately) gets a JMSException (caused
by a ConnectionException) with the reason being that the connection is
refused.

However, in debugging, I noticed that if one uses the DEFAULT connection
URL, these parameters are ignored and the default TCP URL of
tcp://localhost:61616 is actually failover://tcp://localhost:61616.

It's not obvious to me yet what the significance of the failover protocol
actually means, but I'm still digging.


icfantv wrote:
> 
> Hi-
> 
> Did a cursory search but didn't find anything related to this so I
> apologize in advance if it's been asked and answered - I didn't see it.
> 
> Is there a way to set a connection timeout on the connection factory class
> such that the thread doesn't block until a connection is successfully
> made?  I see several timeout related methods in the connection object but
> don't see anything specifically related to connection timeouts.
> 
> Thanks in advance,
> 
> --adam
> 

-- 
View this message in context: http://www.nabble.com/Connection-creation-timeout-setting-tp21490199p21507617.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.