public class RabbitRpcClient extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RabbitRpcClient.RabbitRpcClientConsumer
Internal implementation of a Consumer that receives messages on the reply
queue and calls
processResponseForRequest(String, byte[]) of its
RabbitRpcClient.RabbitRpcClientConsumer.client. |
protected static class |
RabbitRpcClient.RabbitRpcRequest
Simple extension of the
AbstractFuture class that waits for the
response which is set by the RabbitRpcClient.RabbitRpcRequest.setResponse(byte[] response). |
| Modifier and Type | Field and Description |
|---|---|
private Map<String,RabbitRpcClient.RabbitRpcRequest> |
currentRequests
Mapping of correlation Ids to their
RabbitRpcClient.RabbitRpcRequest instances. |
private static long |
DEFAULT_MAX_WAITING_TIME
The default maximum amount of time in millisecond the client is waiting
for a response = 600000Lms.
|
private static org.slf4j.Logger |
LOGGER |
private long |
maxWaitingTime
The maximum amount of time in millisecond the client is waiting for a
response.
|
private Semaphore |
requestMapMutex
Mutex for managing access to the
currentRequests object. |
private RabbitQueue |
requestQueue
Queue used for the request.
|
private RabbitQueue |
responseQueue
Queue used for the responses.
|
| Modifier | Constructor and Description |
|---|---|
protected |
RabbitRpcClient()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static RabbitRpcClient |
create(com.rabbitmq.client.Connection connection,
String requestQueueName)
Creates a StorageServiceClient using the given RabbitMQ
Connection. |
long |
getMaxWaitingTime() |
protected void |
init(com.rabbitmq.client.Connection connection,
String requestQueueName)
Initializes the client by declaring a request queue using the given
connection and queue name as well as a second queue and a consumer for
retrieving responses.
|
protected void |
processResponseForRequest(String corrId,
byte[] body)
Processes the response with the given correlation Id and byte array by
searching for a matching request and setting the response if it could be
found.
|
byte[] |
request(byte[] data)
Sends the request, i.e., the given data, and blocks until the response is
received.
|
void |
setMaxWaitingTime(long maxWaitingTime)
Sets the maximum amount of time the client is waiting for a response.
|
private static final org.slf4j.Logger LOGGER
private static final long DEFAULT_MAX_WAITING_TIME
private RabbitQueue requestQueue
private RabbitQueue responseQueue
private Semaphore requestMapMutex
currentRequests object.private Map<String,RabbitRpcClient.RabbitRpcRequest> currentRequests
RabbitRpcClient.RabbitRpcRequest instances.private long maxWaitingTime
DEFAULT_MAX_WAITING_TIME.public static RabbitRpcClient create(com.rabbitmq.client.Connection connection, String requestQueueName) throws IOException
Connection.connection - RabbitMQ connection used for the communicationrequestQueueName - name of the queue to which the requests should be sentIOException - if a problem occurs during the creation of the queues or the
consumer.protected void init(com.rabbitmq.client.Connection connection,
String requestQueueName)
throws IOException
connection - the RabbitMQ connection that is used for creating queuesrequestQueueName - the name of the queueIOException - if a communication problem during the creation of the
channel, the queue or the internal consumer occurspublic byte[] request(byte[] data)
data - the data of the requestprotected void processResponseForRequest(String corrId, byte[] body)
corrId - correlation Id of the responsebody - data of the responsepublic long getMaxWaitingTime()
public void setMaxWaitingTime(long maxWaitingTime)
maxWaitingTime - the maximum waiting time in millisecondspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2017–2018. All rights reserved.