Package com.rabbitmq.client
Class RpcServer
java.lang.Object
com.rabbitmq.client.RpcServer
- Direct Known Subclasses:
MapRpcServer,StringRpcServer
Class which manages a request queue for a simple RPC-style service.
The class is agnostic about the format of RPC arguments / return values.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an RpcServer listening on a temporary exclusive autodelete queue.If the passed-in queue name is null, creates a server-named temporary exclusive autodelete queue to use; otherwise expects the queue to have already been declared. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.Retrieve the channel.Retrieve the queue name.byte[]handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties) High-level response method.byte[]handleCall(AMQP.BasicProperties requestProperties, byte[] requestBody, AMQP.BasicProperties replyProperties) Mid-level response method.byte[]handleCall(QueueingConsumer.Delivery request, AMQP.BasicProperties replyProperties) Lowest-level response method.voidhandleCast(byte[] requestBody) High-level handler method.voidhandleCast(AMQP.BasicProperties requestProperties, byte[] requestBody) Mid-level handler method.voidhandleCast(QueueingConsumer.Delivery request) Lowest-level handler method.mainloop()Public API - main server loop.voidprocessRequest(QueueingConsumer.Delivery request) Private API - Process a single request.protected QueueingConsumerRegisters a consumer on the reply queue.voidCall this method to terminate the mainloop.
-
Constructor Details
-
RpcServer
Creates an RpcServer listening on a temporary exclusive autodelete queue.- Throws:
IOException
-
RpcServer
If the passed-in queue name is null, creates a server-named temporary exclusive autodelete queue to use; otherwise expects the queue to have already been declared.- Throws:
IOException
-
-
Method Details
-
close
Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.- Throws:
IOException- if an error is encountered
-
setupConsumer
Registers a consumer on the reply queue.- Returns:
- the newly created and registered consumer
- Throws:
IOException- if an error is encountered
-
mainloop
Public API - main server loop. Call this to begin processing requests. Request processing will continue until the Channel (or its underlying Connection) is shut down, or until terminateMainloop() is called. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler.- Returns:
- the exception that signalled the Channel shutdown, or null for orderly shutdown
- Throws:
IOException
-
terminateMainloop
public void terminateMainloop()Call this method to terminate the mainloop. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler. -
processRequest
Private API - Process a single request. Called from mainloop().- Throws:
IOException
-
handleCall
Lowest-level response method. Calls handleCall(AMQP.BasicProperties,byte[],AMQP.BasicProperties). -
handleCall
public byte[] handleCall(AMQP.BasicProperties requestProperties, byte[] requestBody, AMQP.BasicProperties replyProperties) Mid-level response method. Calls handleCall(byte[],AMQP.BasicProperties). -
handleCall
High-level response method. Returns an empty response by default - override this (or other handleCall and handleCast methods) in subclasses. -
handleCast
Lowest-level handler method. Calls handleCast(AMQP.BasicProperties,byte[]). -
handleCast
Mid-level handler method. Calls handleCast(byte[]). -
handleCast
public void handleCast(byte[] requestBody) High-level handler method. Does nothing by default - override this (or other handleCast and handleCast methods) in subclasses. -
getChannel
Retrieve the channel.- Returns:
- the channel to which this server is connected
-
getQueueName
Retrieve the queue name.- Returns:
- the queue which this server is consuming from
-