[rabbitmq-discuss] Java client problem

Emile Joubert emile at rabbitmq.com
Thu May 27 14:52:32 BST 2010


Hi Jacek,

You are correct that the heartbeat only starts after the connection 
tuning phase of the protocol negotiation so that both peers agree on the 
frequency. It would not make sense to throw a heartbeat exception until 
both peers agreed on a frequency and the heartbeat has started. So I 
don't think it makes sense to set the value any earlier as you suggest.

Can you please confirm what connection retry logic you are referring to 
- is that logic in the com.rabbitmq.client namespace?

Regards

Emile



jacek_ wrote:
> Hi, 
> 
> I am testing currently the Java RabbitMQ client. I want to make sure that
> any problems that can occur with connection to RabbitMQ server will be
> handled properly. To test if everything is working fine I stopped rabbitmq
> server proces (using kill -s SIGSTOP command). This imitate more or less
> problems which can occur in the future. I specified the heartbeat in Java
> client and want to get exceptions when the server does not respond.
> Unfortunatelly when the client tries to connect it enters into endless loop.
> The socket timeout exception is thrown by standard Java socket mechanism but
> RabbitMQ client catch this exception and retry.  No MissedHeartbeatException
> exception is thrown. I have looked into source code of AMQConnection class
> and found that method: 
> 
>     public void handleSocketTimeout() throws MissedHeartbeatException { 
>         if (_heartbeat == 0) { 
>             // No heartbeating. Go back and wait some more. 
>             return; 
>         } 
> 
>         _missedHeartbeats++; 
> 
>         // We check against 8 = 2 * 4 because we need to wait for at 
>         // least two complete heartbeat setting intervals before 
>         // complaining, and we've set the socket timeout to a quarter 
>         // of the heartbeat setting in setHeartbeat above. 
>         if (_missedHeartbeats > (2 * 4)) { 
>             throw new MissedHeartbeatException("Heartbeat missing with
> heartbeat == " + 
>                                                _heartbeat + " seconds"); 
>         } 
>     } 
> 
> 
> The problem is that _heartbeat field is filled with data after connection is
> created (not before). The initial value is 0. Until connection is
> successfully made client will try to connect again and again. Exception will
> never be thrown, so my application will have no information about server
> problems. In my opinion only minor changes are required to make this thing
> work - _hearbeat field should be filled before making the connection. Please
> correct me if I am wrong. 
> 
> Thanks in advance, 
> Jacek 




More information about the rabbitmq-discuss mailing list