[rabbitmq-discuss] RabbitMQ Cilent: Allow specifying the connect timeout

Emile Joubert emile at rabbitmq.com
Wed Oct 27 12:40:33 BST 2010

Hi again Amr,

On 27/10/10 12:01, Emile Joubert wrote:
> Hi Amr,
> On 23/10/10 19:20, Amr Mostafa wrote:
>> Hi,
>> I've been searching around for a way to specify a connect timeout in the
>> Java client, but couldn't find an easy way to do that. There is one way,
>> which is by extending ConnectionFactory with a custom createFrameHandler
>> method, but that doesn't work with my case since I'm using Spring AMQP
>> support on top of the client API.
>> It would be very useful to add an option for that in the
>> ConnectionFactory which, if specified, would be passed to the socket
>> connect call.
> You can also set socket options by overriding
> ConnectionFactory.configureSocket(). By default this hook disables
> Nagle's algorithm, but it can be used to set the timeout as well
> (socket.setSoTimeout()). Even when using Spring AMQP you should be able
> to specify your own ConnectionFactory that inherits from the existing one.

My previous advice won't work, because SO_TIMEOUT doesn't affect the
connection timeout. Instead of overriding configureSocket(), you need to
override createFrameHandler(). The call to socket.connect(addr) needs to
be changed to the 2-parameter version that accepts a connection timeout.

Another option would be to supply your own SocketFactory that supplies
sockets that override connect().

Given the difficulty of both these options we will look at extending the
ConnectionFactory API to make this simpler, as you suggested.



More information about the rabbitmq-discuss mailing list