com.rabbitmq.client
public class RpcClient extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static int |
NO_TIMEOUT
NO_TIMEOUT value must match convention on
BlockingCell.uninterruptibleGet(int) |
Constructor and Description |
---|
RpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey)
Construct a new RpcClient that will communicate on the given channel, sending
requests to the given exchange with the given routing key.
|
RpcClient(Channel channel,
java.lang.String exchange,
java.lang.String routingKey,
int timeout)
Construct a new RpcClient that will communicate on the given channel, sending
requests to the given exchange with the given routing key.
|
Modifier and Type | Method and Description |
---|---|
void |
checkConsumer()
Private API - ensures the RpcClient is correctly open.
|
void |
close()
Public API - cancels the consumer, thus deleting the temporary queue, and marks the RpcClient as closed.
|
Channel |
getChannel()
Retrieve the channel.
|
Consumer |
getConsumer()
Retrieve the consumer.
|
java.util.Map<java.lang.String,BlockingCell<java.lang.Object>> |
getContinuationMap()
Retrieve the continuation map.
|
int |
getCorrelationId()
Retrieve the correlation id.
|
java.lang.String |
getExchange()
Retrieve the exchange.
|
java.lang.String |
getRoutingKey()
Retrieve the routing key.
|
java.util.Map<java.lang.String,java.lang.Object> |
mapCall(java.util.Map<java.lang.String,java.lang.Object> message)
Perform an AMQP wire-protocol-table based RPC roundtrip
There are some restrictions on the values appearing in the table: they must be of type String , LongString , Integer , BigDecimal , Date ,
or (recursively) a Map of the enclosing type. |
java.util.Map<java.lang.String,java.lang.Object> |
mapCall(java.lang.Object[] keyValuePairs)
Perform an AMQP wire-protocol-table based RPC roundtrip, first
constructing the table from an array of alternating keys (in
even-numbered elements, starting at zero) and values (in
odd-numbered elements, starting at one)
Restrictions on value arguments apply as in mapCall(Map) . |
byte[] |
primitiveCall(AMQP.BasicProperties props,
byte[] message) |
byte[] |
primitiveCall(byte[] message)
Perform a simple byte-array-based RPC roundtrip.
|
void |
publish(AMQP.BasicProperties props,
byte[] message) |
protected DefaultConsumer |
setupConsumer()
Registers a consumer on the reply queue.
|
java.lang.String |
stringCall(java.lang.String message)
Perform a simple string-based RPC roundtrip.
|
protected static final int NO_TIMEOUT
BlockingCell.uninterruptibleGet(int)
public RpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey, int timeout) throws java.io.IOException
channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keytimeout
- milliseconds before timing out on wait for responsejava.io.IOException
- if an error is encounteredpublic RpcClient(Channel channel, java.lang.String exchange, java.lang.String routingKey) throws java.io.IOException
channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keyjava.io.IOException
- if an error is encounteredpublic void checkConsumer() throws java.io.IOException
java.io.IOException
- if an error is encounteredpublic void close() throws java.io.IOException
java.io.IOException
- if an error is encounteredprotected DefaultConsumer setupConsumer() throws java.io.IOException
java.io.IOException
- if an error is encounteredpublic void publish(AMQP.BasicProperties props, byte[] message) throws java.io.IOException
java.io.IOException
public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message) throws java.io.IOException, ShutdownSignalException, java.util.concurrent.TimeoutException
java.io.IOException
ShutdownSignalException
java.util.concurrent.TimeoutException
public byte[] primitiveCall(byte[] message) throws java.io.IOException, ShutdownSignalException, java.util.concurrent.TimeoutException
message
- the byte array request message to sendShutdownSignalException
- if the connection dies during our waitjava.io.IOException
- if an error is encounteredjava.util.concurrent.TimeoutException
- if a response is not received within the configured timeoutpublic java.lang.String stringCall(java.lang.String message) throws java.io.IOException, ShutdownSignalException, java.util.concurrent.TimeoutException
message
- the string request message to sendShutdownSignalException
- if the connection dies during our waitjava.io.IOException
- if an error is encounteredjava.util.concurrent.TimeoutException
- if a timeout occurs before the response is receivedpublic java.util.Map<java.lang.String,java.lang.Object> mapCall(java.util.Map<java.lang.String,java.lang.Object> message) throws java.io.IOException, ShutdownSignalException, java.util.concurrent.TimeoutException
String
, LongString
, Integer
, BigDecimal
, Date
,
or (recursively) a Map
of the enclosing type.message
- the table to sendShutdownSignalException
- if the connection dies during our waitjava.io.IOException
- if an error is encounteredjava.util.concurrent.TimeoutException
- if a timeout occurs before a response is receivedpublic java.util.Map<java.lang.String,java.lang.Object> mapCall(java.lang.Object[] keyValuePairs) throws java.io.IOException, ShutdownSignalException, java.util.concurrent.TimeoutException
mapCall(Map)
.keyValuePairs
- alternating {key, value, key, value, ...} data to sendShutdownSignalException
- if the connection dies during our waitjava.io.IOException
- if an error is encounteredjava.util.concurrent.TimeoutException
- if a timeout occurs before a response is receivedpublic Channel getChannel()
public java.lang.String getExchange()
public java.lang.String getRoutingKey()
public java.util.Map<java.lang.String,BlockingCell<java.lang.Object>> getContinuationMap()
public int getCorrelationId()
public Consumer getConsumer()