public class

RpcClient

extends Object
java.lang.Object
   ↳ com.rabbitmq.client.RpcClient
Known Direct Subclasses

Class Overview

Convenience class which manages a temporary reply queue for simple RPC-style communication. The class is agnostic about the format of RPC arguments / return values. It simply provides a mechanism for sending a message to an exchange with a given routing key, and waiting for a response on a reply queue.

Summary

Constants
int NO_TIMEOUT NO_TIMEOUT value must match convention on uninterruptibleGet(int)
Public Constructors
RpcClient(Channel channel, String exchange, 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.
RpcClient(Channel channel, String exchange, String routingKey)
Construct a new RpcClient that will communicate on the given channel, sending requests to the given exchange with the given routing key.
Public Methods
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.
Map<StringBlockingCell<Object>> getContinuationMap()
Retrieve the continuation map.
int getCorrelationId()
Retrieve the correlation id.
String getExchange()
Retrieve the exchange.
String getReplyQueue()
Retrieve the reply queue.
String getRoutingKey()
Retrieve the routing key.
Map<StringObject> mapCall(Map<StringObject> 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, java.math.BigDecimal, Date, or (recursively) a Map of the enclosing type.
Map<StringObject> mapCall(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(byte[] message)
Perform a simple byte-array-based RPC roundtrip.
byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
void publish(AMQP.BasicProperties props, byte[] message)
String stringCall(String message)
Perform a simple string-based RPC roundtrip.
Protected Methods
DefaultConsumer setupConsumer()
Registers a consumer on the reply queue.
String setupReplyQueue()
Creates a server-named exclusive autodelete queue to use for receiving replies to RPC requests.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

protected static final int NO_TIMEOUT

NO_TIMEOUT value must match convention on uninterruptibleGet(int)

Constant Value: -1 (0xffffffff)

Public Constructors

public RpcClient (Channel channel, String exchange, 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.

Causes the creation of a temporary private autodelete queue.

Parameters
channel the channel to use for communication
exchange the exchange to connect to
routingKey the routing key
timeout milliseconds before timing out on wait for response
Throws
IOException if an error is encountered

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

Construct a new RpcClient that will communicate on the given channel, sending requests to the given exchange with the given routing key.

Causes the creation of a temporary private autodelete queue.

Waits forever for responses (that is, no timeout).

Parameters
channel the channel to use for communication
exchange the exchange to connect to
routingKey the routing key
Throws
IOException if an error is encountered

Public Methods

public void checkConsumer ()

Private API - ensures the RpcClient is correctly open.

Throws
IOException if an error is encountered

public void close ()

Public API - cancels the consumer, thus deleting the temporary queue, and marks the RpcClient as closed.

Throws
IOException if an error is encountered

public Channel getChannel ()

Retrieve the channel.

Returns
  • the channel to which this client is connected

public Consumer getConsumer ()

Retrieve the consumer.

Returns
  • an interface to the client's consumer object

public Map<StringBlockingCell<Object>> getContinuationMap ()

Retrieve the continuation map.

Returns
  • the map of objects to blocking cells for this client

public int getCorrelationId ()

Retrieve the correlation id.

Returns
  • the most recently used correlation id

public String getExchange ()

Retrieve the exchange.

Returns
  • the exchange to which this client is connected

public String getReplyQueue ()

Retrieve the reply queue.

Returns
  • the name of the client's reply queue

public String getRoutingKey ()

Retrieve the routing key.

Returns
  • the routing key for messages to this client

public Map<StringObject> mapCall (Map<StringObject> 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, java.math.BigDecimal, Date, or (recursively) a Map of the enclosing type.

Parameters
message the table to send
Returns
  • the table received
Throws
ShutdownSignalException if the connection dies during our wait
IOException if an error is encountered
TimeoutException if a timeout occurs before a response is received

public Map<StringObject> mapCall (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).

Parameters
keyValuePairs alternating {key, value, key, value, ...} data to send
Returns
  • the table received
Throws
ShutdownSignalException if the connection dies during our wait
IOException if an error is encountered
TimeoutException if a timeout occurs before a response is received

public byte[] primitiveCall (byte[] message)

Perform a simple byte-array-based RPC roundtrip.

Parameters
message the byte array request message to send
Returns
  • the byte array response received
Throws
ShutdownSignalException if the connection dies during our wait
IOException if an error is encountered
TimeoutException if a response is not received within the configured timeout

public byte[] primitiveCall (AMQP.BasicProperties props, byte[] message)

public void publish (AMQP.BasicProperties props, byte[] message)

Throws
IOException

public String stringCall (String message)

Perform a simple string-based RPC roundtrip.

Parameters
message the string request message to send
Returns
  • the string response received
Throws
ShutdownSignalException if the connection dies during our wait
IOException if an error is encountered
TimeoutException if a timeout occurs before the response is received

Protected Methods

protected DefaultConsumer setupConsumer ()

Registers a consumer on the reply queue.

Returns
  • the newly created and registered consumer
Throws
IOException if an error is encountered

protected String setupReplyQueue ()

Creates a server-named exclusive autodelete queue to use for receiving replies to RPC requests.

Returns
  • the name of the reply queue
Throws
IOException if an error is encountered