[rabbitmq-discuss] Can Java API JsonRpcClient know server not exist?

Jerry Kuch jerryk at vmware.com
Tue Nov 16 15:59:00 GMT 2010


Hi, Cui...

I'm run RabbitMQ Java client 2.1.1 examples HelloJsonServer and HelloJsonClient. The RabbitMQ Server's version is 2.1.1.
My question is if HelloJsonServer program not running, I start up HelloJsonClient first, the process will be blocked.
Is there a way to set a timeout or exception, when HelloJsonClient send the request and HelloJsonServer not exist the function will throw an exception tell me JsonRpcClient waiting response time out or the request server not exist?

At present neither JsonRpcClient, nor RpcClient which it extends, supports a timeout to stop the constructor from blocking in the way you want.  This would be a nice thing to have, so we'll put it in as a bug/feature request for a future release.

If you want a short term remedy, you could try creating a subclass of JsonRpcClient, in which you have a new constructor that takes your timeout and stores it in a field, and then overriding primitiveCall (which is inherited from RpcClient.java) with a method that calls the version of uninterruptibleGet that takes an integer timeout as its argument rather than the nullary one that's currently called.  Although perhaps not the prettiest thing to have to do in end user code, it will at least get you out of your current situation.

Jerry




More information about the rabbitmq-discuss mailing list