Package com.rabbitmq.tools.jsonrpc
Class JsonRpcClient
java.lang.Object
com.rabbitmq.client.RpcClient
com.rabbitmq.tools.jsonrpc.JsonRpcClient
- All Implemented Interfaces:
AutoCloseable
,InvocationHandler
JSON-RPC is a lightweight
RPC mechanism using JSON
as a data language for request and reply messages. It is
rapidly becoming a standard in web development, where it is
used to make RPC requests over HTTP. RabbitMQ provides an
AMQP transport binding for JSON-RPC in the form of the
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.
JsonRpcClient
delegates JSON parsing and generating to
a JsonRpcMapper
.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.rabbitmq.client.RpcClient
RpcClient.Response
-
Field Summary
Fields inherited from class com.rabbitmq.client.RpcClient
DEFAULT_REPLY_HANDLER, NO_TIMEOUT
-
Constructor Summary
ConstructorDescriptionJsonRpcClient
(Channel channel, String exchange, String routingKey) JsonRpcClient
(Channel channel, String exchange, String routingKey, int timeout) Construct a new JsonRpcClient, passing the parameters through to RpcClient's constructor.JsonRpcClient
(Channel channel, String exchange, String routingKey, int timeout, JsonRpcMapper mapper) Construct a new JsonRpcClient, passing the parameters through to RpcClient's constructor.JsonRpcClient
(RpcClientParams rpcClientParams, JsonRpcMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.This method will be removed in the next major versionPublic API - builds, encodes and sends a JSON-RPC request, and waits for the response.static Object
Deprecated.This method will be removed in the next major version<T> T
createProxy
(Class<T> klass) Public API - gets a dynamic proxy for a particular interface class.Public API - gets the service description record that this service loaded from the server itself at construction time.Public API - implements InvocationHandler.invoke.Methods inherited from class com.rabbitmq.client.RpcClient
close, doCall, doCall, getChannel, getConsumer, getContinuationMap, getCorrelationId, getExchange, getRoutingKey, incrementingCorrelationIdSupplier, incrementingCorrelationIdSupplier, mapCall, mapCall, primitiveCall, primitiveCall, primitiveCall, publish, responseCall, responseCall, setupConsumer, stringCall
-
Constructor Details
-
JsonRpcClient
public JsonRpcClient(RpcClientParams rpcClientParams, JsonRpcMapper mapper) throws IOException, JsonRpcException, TimeoutException Construct a newJsonRpcClient
, passing theRpcClientParams
throughRpcClient
's constructor.The service description record is retrieved from the server during construction.
- Parameters:
rpcClientParams
-mapper
-- Throws:
IOException
JsonRpcException
TimeoutException
-
JsonRpcClient
public JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout, JsonRpcMapper mapper) throws IOException, JsonRpcException, TimeoutException Construct a new JsonRpcClient, passing the parameters through to RpcClient's constructor. The service description record is retrieved from the server during construction.- Throws:
TimeoutException
- if a response is not received within the timeout specified, if anyIOException
JsonRpcException
-
JsonRpcClient
public JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout) throws IOException, JsonRpcException, TimeoutException Construct a new JsonRpcClient, passing the parameters through to RpcClient's constructor. The service description record is retrieved from the server during construction.- Throws:
TimeoutException
- if a response is not received within the timeout specified, if anyIOException
JsonRpcException
-
JsonRpcClient
public JsonRpcClient(Channel channel, String exchange, String routingKey) throws IOException, JsonRpcException, TimeoutException
-
-
Method Details
-
coerce
Deprecated.This method will be removed in the next major versionPrivate API - used bycall(String[])
to ad-hoc convert strings into the required data types for a call. This method is deprecated because it uses homegrown JSON utilities that don't deal correctly with complex types. TheJacksonJsonRpcMapper
has been introduced to handle primitive and complex types, as well as primitive wrappers correctly.- Throws:
NumberFormatException
-
call
public Object call(String method, Object[] params) throws IOException, JsonRpcException, TimeoutException Public API - builds, encodes and sends a JSON-RPC request, and waits for the response.- Returns:
- the result contained within the reply, if no exception is found
- Throws:
JsonRpcException
- if the reply object contained an exceptionTimeoutException
- if a response is not received within the timeout specified, if anyIOException
-
invoke
Public API - implements InvocationHandler.invoke. This is useful for constructing dynamic proxies for JSON-RPC interfaces.- Specified by:
invoke
in interfaceInvocationHandler
- Throws:
Throwable
-
createProxy
Public API - gets a dynamic proxy for a particular interface class.- Throws:
IllegalArgumentException
-
call
@Deprecated public Object call(String[] args) throws NumberFormatException, IOException, JsonRpcException, TimeoutException Deprecated.This method will be removed in the next major versionPublic API - ascall(String, Object[])
, but takes the method name from the first entry inargs
, and the parameters from subsequent entries. All parameter values are passed through coerce() to attempt to make them the types the server is expecting. This method is deprecated because it uses homegrown JSON utilities that don't deal correctly with complex types. TheJacksonJsonRpcMapper
has been introduced to handle primitive and complex types, as well as primitive wrappers correctly.- Returns:
- the result contained within the reply, if no exception is found
- Throws:
JsonRpcException
- if the reply object contained an exceptionNumberFormatException
- if a coercion failedTimeoutException
- if a response is not received within the timeout specified, if anyIOException
- See Also:
-
getServiceDescription
Public API - gets the service description record that this service loaded from the server itself at construction time.
-