com.rabbitmq.tools.jsonrpc
public class JsonRpcClient extends RpcClient implements java.lang.reflect.InvocationHandler
JsonRpcClient class.
JSON-RPC services are self-describing - each service is able
to list its supported procedures, and each procedure
describes its parameters and types. An instance of
JsonRpcClient retrieves its service description using the
standard system.describe procedure when it is
constructed, and uses the information to coerce parameter
types appropriately. A JSON service description is parsed
into instances of ServiceDescription. Client
code can access the service description by reading the
serviceDescription field of
JsonRpcClient instances.call(String, Object[]),
call(String[])NO_TIMEOUT| Constructor and Description |
|---|
JsonRpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey) |
JsonRpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey,
int timeout)
Construct a new JsonRpcClient, passing the parameters through
to RpcClient's constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
call(java.lang.String[] args)
Public API - as
call(String,Object[]), but takes the
method name from the first entry in args, and the
parameters from subsequent entries. |
java.lang.Object |
call(java.lang.String method,
java.lang.Object[] params)
Public API - builds, encodes and sends a JSON-RPC request, and
waits for the response.
|
static java.lang.Object |
checkReply(java.util.Map<java.lang.String,java.lang.Object> reply)
Private API - parses a JSON-RPC reply object, checking it for exceptions.
|
static java.lang.Object |
coerce(java.lang.String val,
java.lang.String type)
Private API - used by
call(String[]) to ad-hoc convert
strings into the required data types for a call. |
java.lang.Object |
createProxy(java.lang.Class<?> klass)
Public API - gets a dynamic proxy for a particular interface class.
|
ServiceDescription |
getServiceDescription()
Public API - gets the service description record that this
service loaded from the server itself at construction time.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Public API - implements InvocationHandler.invoke.
|
checkConsumer, close, getChannel, getConsumer, getContinuationMap, getCorrelationId, getExchange, getRoutingKey, mapCall, mapCall, primitiveCall, primitiveCall, publish, setupConsumer, stringCallpublic JsonRpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey, int timeout) throws java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException - if a response is not received within the timeout specified, if anyjava.io.IOExceptionJsonRpcExceptionpublic JsonRpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey) throws java.io.IOException, JsonRpcException, java.util.concurrent.TimeoutException
java.io.IOExceptionJsonRpcExceptionjava.util.concurrent.TimeoutExceptionpublic static java.lang.Object checkReply(java.util.Map<java.lang.String,java.lang.Object> reply)
throws JsonRpcException
JsonRpcExceptionpublic java.lang.Object call(java.lang.String method,
java.lang.Object[] params)
throws java.io.IOException,
JsonRpcException,
java.util.concurrent.TimeoutException
JsonRpcException - if the reply object contained an exceptionjava.util.concurrent.TimeoutException - if a response is not received within the timeout specified, if anyjava.io.IOExceptionpublic java.lang.Object invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.Throwable
invoke in interface java.lang.reflect.InvocationHandlerjava.lang.Throwablepublic java.lang.Object createProxy(java.lang.Class<?> klass)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic static java.lang.Object coerce(java.lang.String val,
java.lang.String type)
throws java.lang.NumberFormatException
call(String[]) to ad-hoc convert
strings into the required data types for a call.java.lang.NumberFormatExceptionpublic java.lang.Object call(java.lang.String[] args)
throws java.lang.NumberFormatException,
java.io.IOException,
JsonRpcException,
java.util.concurrent.TimeoutException
call(String,Object[]), but takes the
method name from the first entry in args, and the
parameters from subsequent entries. All parameter values are
passed through coerce() to attempt to make them the types the
server is expecting.JsonRpcException - if the reply object contained an exceptionjava.lang.NumberFormatException - if a coercion failedjava.util.concurrent.TimeoutException - if a response is not received within the timeout specified, if anyjava.io.IOExceptioncoerce(java.lang.String, java.lang.String)public ServiceDescription getServiceDescription()