com.rabbitmq.client
Class RpcClient

java.lang.Object
  extended by com.rabbitmq.client.RpcClient
Direct Known Subclasses:
JsonRpcClient

public class RpcClient
extends java.lang.Object

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.


Constructor Summary
RpcClient(Channel channel, int ticket, java.lang.String exchange, java.lang.String routingKey)
          Construct a new RpcClient that will communicate on the given channel, using the given ticket for permission, sending requests to the given exchange with the given routing key.
 
Method Summary
 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 getReplyQueue()
          Retrieve the reply queue.
 java.lang.String getRoutingKey()
          Retrieve the routing key.
 int getTicket()
          Retrieve the access ticket.
 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)
           
 java.lang.String stringCall(java.lang.String message)
          Perform a simple string-based RPC roundtrip.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RpcClient

public RpcClient(Channel channel,
                 int ticket,
                 java.lang.String exchange,
                 java.lang.String routingKey)
          throws java.io.IOException
Construct a new RpcClient that will communicate on the given channel, using the given ticket for permission, 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
ticket - the access ticket for the appropriate realm
exchange - the exchange to connect to
routingKey - the routing key
Throws:
java.io.IOException - if an error is encountered
See Also:
setupReplyQueue()
Method Detail

checkConsumer

public void checkConsumer()
                   throws java.io.IOException
Private API - ensures the RpcClient is correctly open.

Throws:
java.io.IOException - if an error is encountered

close

public void close()
           throws java.io.IOException
Public API - cancels the consumer, thus deleting the temporary queue, and marks the RpcClient as closed.

Throws:
java.io.IOException - if an error is encountered

publish

public void publish(AMQP.BasicProperties props,
                    byte[] message)
             throws java.io.IOException
Throws:
java.io.IOException

primitiveCall

public byte[] primitiveCall(AMQP.BasicProperties props,
                            byte[] message)
                     throws java.io.IOException,
                            ShutdownSignalException
Throws:
java.io.IOException
ShutdownSignalException

primitiveCall

public byte[] primitiveCall(byte[] message)
                     throws java.io.IOException,
                            ShutdownSignalException
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
java.io.IOException - if an error is encountered

stringCall

public java.lang.String stringCall(java.lang.String message)
                            throws java.io.IOException,
                                   ShutdownSignalException
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
java.io.IOException - if an error is encountered

mapCall

public 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
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.

Parameters:
message - the table to send
Returns:
the table received
Throws:
ShutdownSignalException - if the connection dies during our wait
java.io.IOException - if an error is encountered

mapCall

public java.util.Map<java.lang.String,java.lang.Object> mapCall(java.lang.Object[] keyValuePairs)
                                                         throws java.io.IOException,
                                                                ShutdownSignalException
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
java.io.IOException - if an error is encountered

getChannel

public Channel getChannel()
Retrieve the channel.

Returns:
the channel to which this client is connected

getTicket

public int getTicket()
Retrieve the access ticket.

Returns:
the access ticket for the appropriate realm

getExchange

public java.lang.String getExchange()
Retrieve the exchange.

Returns:
the exchange to which this client is connected

getRoutingKey

public java.lang.String getRoutingKey()
Retrieve the routing key.

Returns:
the routing key for messages to this client

getContinuationMap

public java.util.Map<java.lang.String,BlockingCell<java.lang.Object>> getContinuationMap()
Retrieve the continuation map.

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

getCorrelationId

public int getCorrelationId()
Retrieve the correlation id.

Returns:
the most recently used correlation id

getReplyQueue

public java.lang.String getReplyQueue()
Retrieve the reply queue.

Returns:
the name of the client's reply queue

getConsumer

public Consumer getConsumer()
Retrieve the consumer.

Returns:
an interface to the client's consumer object