[rabbitmq-discuss] Java client problem

Emile Joubert emile at rabbitmq.com
Thu May 27 17:58:52 BST 2010

Hi Jacek,

The core rabbit java client produces a ShutdownSignalException if a 
java.io.EOFException occurs, providing notification of network problems 
in the scenario you describe.

If the reconnect logic you refer to is in the com.rabbitmq.client 
namespace then I assume you are using the messagepatterns library. This 
library aims to provide generic message patterns (including connection 
reliability) that are typically implemented on top of the core client 
library. If you don't want connection retries then you can lower the 
number of retry attempts or use the core library directly.


Jacek Olszak wrote:
> Hi,
> first of all thanks for quick reply :) I use classes from
> "com.rabbitmq.client" package. The code I pasted here is from class
> com.rabbitmq.client.impl.AMQConnection. My problem is that the client
> will never throw an exception and will hangs indefinitely until the
> server socket is closed or the process will continue to work. My idea
> is that the Java client should throw some exception in such case,
> because it is possible that under very heavy load or network problems
> rabbitmq server will not reply in reasonable amount of time. In such
> case I want to connect to another MQ server.
> Best regards,
> Jacek
> On Thu, May 27, 2010 at 3:52 PM, Emile Joubert <emile at rabbitmq.com> wrote:
>> 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