public class

JsonRpcClient

extends RpcClient
implements InvocationHandler
java.lang.Object
   ↳ com.rabbitmq.client.RpcClient
     ↳ com.rabbitmq.tools.jsonrpc.JsonRpcClient

Class Overview

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.

Summary

[Expand]
Inherited Constants
From class com.rabbitmq.client.RpcClient
Public Constructors
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)
Public Methods
Object call(String method, Object[] params)
Public API - builds, encodes and sends a JSON-RPC request, and waits for the response.
Object call(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.
static Object checkReply(Map<StringObject> reply)
Private API - parses a JSON-RPC reply object, checking it for exceptions.
static Object coerce(String val, String type)
Private API - used by call(String[]) to ad-hoc convert strings into the required data types for a call.
Object createProxy(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.
Object invoke(Object proxy, Method method, Object[] args)
Public API - implements InvocationHandler.invoke.
[Expand]
Inherited Methods
From class com.rabbitmq.client.RpcClient
From class java.lang.Object
From interface java.lang.reflect.InvocationHandler

Public Constructors

public JsonRpcClient (Channel channel, String exchange, String routingKey, int timeout)

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 any
IOException
JsonRpcException

public JsonRpcClient (Channel channel, String exchange, String routingKey)

Public Methods

public Object call (String method, Object[] params)

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 exception
TimeoutException if a response is not received within the timeout specified, if any
IOException

public Object call (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. All parameter values are passed through coerce() to attempt to make them the types the server is expecting.

Returns
  • the result contained within the reply, if no exception is found
Throws
JsonRpcException if the reply object contained an exception
NumberFormatException if a coercion failed
TimeoutException if a response is not received within the timeout specified, if any
IOException

public static Object checkReply (Map<StringObject> reply)

Private API - parses a JSON-RPC reply object, checking it for exceptions.

Returns
  • the result contained within the reply, if no exception is found Throws JsonRpcException if the reply object contained an exception

public static Object coerce (String val, String type)

Private API - used by call(String[]) to ad-hoc convert strings into the required data types for a call.

public Object createProxy (Class<?> klass)

Public API - gets a dynamic proxy for a particular interface class.

public ServiceDescription getServiceDescription ()

Public API - gets the service description record that this service loaded from the server itself at construction time.

public Object invoke (Object proxy, Method method, Object[] args)

Public API - implements InvocationHandler.invoke. This is useful for constructing dynamic proxies for JSON-RPC interfaces.

Throws
Throwable