public class RpcClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RpcClient.Response
The response object is an envelope that contains all of the data provided to the `handleDelivery` consumer
|
Modifier and Type | Field and Description |
---|---|
static Function<Object,RpcClient.Response> |
DEFAULT_REPLY_HANDLER |
protected static int |
NO_TIMEOUT
NO_TIMEOUT value must match convention on
BlockingCell.uninterruptibleGet(int) |
Constructor and Description |
---|
RpcClient(Channel channel,
String exchange,
String routingKey)
Deprecated.
use
RpcClient(RpcClientParams) instead, will be removed in 6.0.0 |
RpcClient(Channel channel,
String exchange,
String routingKey,
int timeout)
Deprecated.
use
RpcClient(RpcClientParams) instead, will be removed in 6.0.0 |
RpcClient(Channel channel,
String exchange,
String routingKey,
String replyTo)
Deprecated.
use
RpcClient(RpcClientParams) instead, will be removed in 6.0.0 |
RpcClient(Channel channel,
String exchange,
String routingKey,
String replyTo,
int timeout)
Deprecated.
use
RpcClient(RpcClientParams) instead, will be removed in 6.0.0 |
RpcClient(RpcClientParams params)
Construct a
RpcClient with the passed-in RpcClientParams . |
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.
|
RpcClient.Response |
doCall(AMQP.BasicProperties props,
byte[] message) |
RpcClient.Response |
doCall(AMQP.BasicProperties props,
byte[] message,
int timeout) |
Channel |
getChannel()
Retrieve the channel.
|
Consumer |
getConsumer()
Retrieve the consumer.
|
Map<String,BlockingCell<Object>> |
getContinuationMap()
Retrieve the continuation map.
|
int |
getCorrelationId()
Retrieve the last correlation id used.
|
String |
getExchange()
Retrieve the exchange.
|
String |
getRoutingKey()
Retrieve the routing key.
|
static Supplier<String> |
incrementingCorrelationIdSupplier()
Creates generation IDs as a sequence of integers.
|
static Supplier<String> |
incrementingCorrelationIdSupplier(String prefix)
Creates generation IDs as a sequence of integers, with the provided prefix.
|
Map<String,Object> |
mapCall(Map<String,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. |
Map<String,Object> |
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(AMQP.BasicProperties props,
byte[] message) |
byte[] |
primitiveCall(AMQP.BasicProperties props,
byte[] message,
int timeout) |
byte[] |
primitiveCall(byte[] message)
Perform a simple byte-array-based RPC roundtrip.
|
void |
publish(AMQP.BasicProperties props,
byte[] message) |
RpcClient.Response |
responseCall(byte[] message)
Perform a simple byte-array-based RPC roundtrip
Useful if you need to get at more than just the body of the message
|
RpcClient.Response |
responseCall(byte[] message,
int timeout)
Perform a simple byte-array-based RPC roundtrip
Useful if you need to get at more than just the body of the message
|
protected DefaultConsumer |
setupConsumer()
Registers a consumer on the reply queue.
|
String |
stringCall(String message)
Perform a simple string-based RPC roundtrip.
|
protected static final int NO_TIMEOUT
BlockingCell.uninterruptibleGet(int)
public static final Function<Object,RpcClient.Response> DEFAULT_REPLY_HANDLER
public RpcClient(RpcClientParams params) throws IOException
RpcClient
with the passed-in RpcClientParams
.params
- IOException
RpcClientParams
@Deprecated public RpcClient(Channel channel, String exchange, String routingKey, String replyTo, int timeout) throws IOException
RpcClient(RpcClientParams)
instead, will be removed in 6.0.0channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keyreplyTo
- the queue where the server should put the replytimeout
- milliseconds before timing out on wait for responseIOException
- if an error is encountered@Deprecated public RpcClient(Channel channel, String exchange, String routingKey, String replyTo) throws IOException
RpcClient(RpcClientParams)
instead, will be removed in 6.0.0channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keyreplyTo
- the queue where the server should put the replyIOException
- if an error is encountered@Deprecated public RpcClient(Channel channel, String exchange, String routingKey) throws IOException
RpcClient(RpcClientParams)
instead, will be removed in 6.0.0channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keyIOException
- if an error is encountered@Deprecated public RpcClient(Channel channel, String exchange, String routingKey, int timeout) throws IOException
RpcClient(RpcClientParams)
instead, will be removed in 6.0.0Construct 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. The name of this queue will be "amq.rabbitmq.reply-to".channel
- the channel to use for communicationexchange
- the exchange to connect toroutingKey
- the routing keytimeout
- milliseconds before timing out on wait for responseIOException
- if an error is encounteredpublic void checkConsumer() throws IOException
IOException
- if an error is encounteredpublic void close() throws IOException
IOException
- if an error is encounteredprotected DefaultConsumer setupConsumer() throws IOException
IOException
- if an error is encounteredpublic void publish(AMQP.BasicProperties props, byte[] message) throws IOException
IOException
public RpcClient.Response doCall(AMQP.BasicProperties props, byte[] message) throws IOException, TimeoutException
IOException
TimeoutException
public RpcClient.Response doCall(AMQP.BasicProperties props, byte[] message, int timeout) throws IOException, ShutdownSignalException, TimeoutException
public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message) throws IOException, ShutdownSignalException, TimeoutException
public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message, int timeout) throws IOException, ShutdownSignalException, TimeoutException
public byte[] primitiveCall(byte[] message) throws IOException, ShutdownSignalException, TimeoutException
message
- the byte array request message to sendShutdownSignalException
- if the connection dies during our waitIOException
- if an error is encounteredTimeoutException
- if a response is not received within the configured timeoutpublic RpcClient.Response responseCall(byte[] message) throws IOException, ShutdownSignalException, TimeoutException
message
- the byte array request message to sendShutdownSignalException
- if the connection dies during our waitIOException
- if an error is encounteredTimeoutException
- if a response is not received within the configured timeoutpublic RpcClient.Response responseCall(byte[] message, int timeout) throws IOException, ShutdownSignalException, TimeoutException
message
- the byte array request message to sendtimeout
- milliseconds before timing out on wait for responseShutdownSignalException
- if the connection dies during our waitIOException
- if an error is encounteredTimeoutException
- if a response is not received within the configured timeoutpublic String stringCall(String message) throws IOException, ShutdownSignalException, TimeoutException
message
- the string request message to sendShutdownSignalException
- if the connection dies during our waitIOException
- if an error is encounteredTimeoutException
- if a timeout occurs before the response is receivedpublic Map<String,Object> mapCall(Map<String,Object> message) throws IOException, ShutdownSignalException, 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 waitIOException
- if an error is encounteredTimeoutException
- if a timeout occurs before a response is receivedpublic Map<String,Object> mapCall(Object[] keyValuePairs) throws IOException, ShutdownSignalException, TimeoutException
mapCall(Map)
.keyValuePairs
- alternating {key, value, key, value, ...} data to sendShutdownSignalException
- if the connection dies during our waitIOException
- if an error is encounteredTimeoutException
- if a timeout occurs before a response is receivedpublic Channel getChannel()
public String getExchange()
public String getRoutingKey()
public Map<String,BlockingCell<Object>> getContinuationMap()
public int getCorrelationId()
Note as of 5.9.0, correlation IDs may not always be integers
(by default, they are).
This method will try to parse the last correlation ID string
as an integer, so this may result in NumberFormatException
if the correlation ID supplier provided by
RpcClientParams.correlationIdSupplier(Supplier)
does not generate appropriate IDs.
RpcClientParams.correlationIdSupplier(Supplier)
public Consumer getConsumer()
public static Supplier<String> incrementingCorrelationIdSupplier()
RpcClientParams.correlationIdSupplier(Supplier)
public static Supplier<String> incrementingCorrelationIdSupplier(String prefix)
prefix
- RpcClientParams.correlationIdSupplier(Supplier)
Copyright © 2022 VMware, Inc. or its affiliates.. All rights reserved.