Class JsonRpcServer
java.lang.Object
com.rabbitmq.client.RpcServer
com.rabbitmq.client.StringRpcServer
com.rabbitmq.tools.jsonrpc.JsonRpcServer
JSON-RPC Server class.
Given a Java Class, representing an interface, and an
implementation of that interface, JsonRpcServer will reflect on the
class to construct the ServiceDescription, and will route
incoming requests for methods on the interface to the
implementation object while the mainloop() is running.
JsonRpcServer delegates JSON parsing and generating to
a JsonRpcMapper.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class RpcServer
RpcServer.RpcConsumer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ObjectThe instance backing this server.private static final org.slf4j.Loggerprivate final JsonRpcMapperprivate ServiceDescriptionHolds the JSON-RPC service description for this client.Fields inherited from class StringRpcServer
STRING_ENCODING -
Constructor Summary
ConstructorsConstructorDescriptionJsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance) Construct a server that talks to the outside world using the given channel, and constructs a fresh temporary queue.JsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance) Construct a server that talks to the outside world using the given channel and queue name.JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptionRuns a single JSON-RPC request.private StringerrorResponse(Object id, int code, String message, Object errorArg) Construct and encode a JSON-RPC error response for the request ID given, using the code, message, and possible (JSON-encodable) argument passed in.Public API - gets the service description record that this service built from interfaceClass at construction time.handleStringCall(String requestBody, AMQP.BasicProperties replyProperties) Override our superclass' method, dispatching to doCall.private voidmatchingMethod(String methodName, Object[] params) Retrieves the best matching method for the given method name and parameters.private StringPrivate API - used by errorResponse and resultResponse.private StringresultResponse(Object id, Object result) Construct and encode a JSON-RPC success response for the request ID given, using the result value passed in.Methods inherited from class StringRpcServer
handleCall, handleCast, handleStringCall, handleStringCastMethods inherited from class RpcServer
close, getChannel, getQueueName, handleCall, handleCall, handleCast, handleCast, mainloop, postprocessReplyProperties, preprocessReplyProperties, processRequest, setupConsumer, terminateMainloop
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
mapper
-
serviceDescription
Holds the JSON-RPC service description for this client. -
interfaceInstance
The instance backing this server.
-
-
Constructor Details
-
JsonRpcServer
public JsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) throws IOException - Throws:
IOException
-
JsonRpcServer
public JsonRpcServer(Channel channel, Class<?> interfaceClass, Object interfaceInstance) throws IOException Construct a server that talks to the outside world using the given channel, and constructs a fresh temporary queue. Use getQueueName() to discover the created queue name.- Parameters:
channel- AMQP channel to useinterfaceClass- Java interface that this server is exposing to the worldinterfaceInstance- Java instance (of interfaceClass) that is being exposed- Throws:
IOException- if something goes wrong during an AMQP operation
-
JsonRpcServer
public JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance, JsonRpcMapper mapper) throws IOException - Throws:
IOException
-
JsonRpcServer
public JsonRpcServer(Channel channel, String queueName, Class<?> interfaceClass, Object interfaceInstance) throws IOException Construct a server that talks to the outside world using the given channel and queue name. Our superclass, RpcServer, expects the queue to exist at the time of construction.- Parameters:
channel- AMQP channel to usequeueName- AMQP queue name to listen for requests oninterfaceClass- Java interface that this server is exposing to the worldinterfaceInstance- Java instance (of interfaceClass) that is being exposed- Throws:
IOException- if something goes wrong during an AMQP operation
-
-
Method Details
-
init
-
handleStringCall
Override our superclass' method, dispatching to doCall.- Overrides:
handleStringCallin classStringRpcServer
-
doCall
-
matchingMethod
-
errorResponse
-
resultResponse
-
response
-
getServiceDescription
Public API - gets the service description record that this service built from interfaceClass at construction time.
-