public class AsyncRabbitTemplate extends java.lang.Object implements org.springframework.amqp.core.AsyncAmqpTemplate, ChannelAwareMessageListener, RabbitTemplate.ReturnCallback, RabbitTemplate.ConfirmCallback, org.springframework.beans.factory.BeanNameAware, org.springframework.context.SmartLifecycle
ListenableFuture
allowing the caller to obtain the reply later, using get() or a callback.
When confirms are enabled, the future has a confirm property which is itself a
ListenableFuture. If the reply is received before the publisher confirm,
the confirm is discarded since the reply implicitly indicates the message was
published.
Returned (undeliverable) request messages are presented as a
AmqpMessageReturnedException cause of an
ExecutionException.
Internally, the template uses a RabbitTemplate and an
AbstractMessageListenerContainer either provided or constructed internally
(a SimpleMessageListenerContainer).
If an external RabbitTemplate is provided and confirms/returns are enabled,
it must not previously have had callbacks registered because this object needs to
be the callback.
| Modifier and Type | Class and Description |
|---|---|
class |
AsyncRabbitTemplate.RabbitConverterFuture<C>
A
AsyncRabbitTemplate.RabbitFuture with a return type of the template's
generic parameter. |
class |
AsyncRabbitTemplate.RabbitFuture<T>
Base class for
ListenableFutures returned by AsyncRabbitTemplate. |
class |
AsyncRabbitTemplate.RabbitMessageFuture
A
AsyncRabbitTemplate.RabbitFuture with a return type of Message. |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_RECEIVE_TIMEOUT |
| Constructor and Description |
|---|
AsyncRabbitTemplate(ConnectionFactory connectionFactory,
java.lang.String exchange,
java.lang.String routingKey)
Construct an instance using the provided arguments.
|
AsyncRabbitTemplate(ConnectionFactory connectionFactory,
java.lang.String exchange,
java.lang.String routingKey,
java.lang.String replyQueue)
Construct an instance using the provided arguments.
|
AsyncRabbitTemplate(ConnectionFactory connectionFactory,
java.lang.String exchange,
java.lang.String routingKey,
java.lang.String replyQueue,
java.lang.String replyAddress)
Construct an instance using the provided arguments.
|
AsyncRabbitTemplate(RabbitTemplate template)
Construct an instance using the provided arguments.
|
AsyncRabbitTemplate(RabbitTemplate template,
AbstractMessageListenerContainer container)
Construct an instance using the provided arguments.
|
AsyncRabbitTemplate(RabbitTemplate template,
AbstractMessageListenerContainer container,
java.lang.String replyAddress)
Construct an instance using the provided arguments.
|
| Modifier and Type | Method and Description |
|---|---|
void |
confirm(CorrelationData correlationData,
boolean ack,
java.lang.String cause)
Confirmation callback.
|
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.Object object) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.String routingKey,
java.lang.Object object) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.String routingKey,
java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.String exchange,
java.lang.String routingKey,
java.lang.Object object) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceive(java.lang.String exchange,
java.lang.String routingKey,
java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.Object object,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.String routingKey,
java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.String routingKey,
java.lang.Object object,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.String exchange,
java.lang.String routingKey,
java.lang.Object object,
org.springframework.amqp.core.MessagePostProcessor messagePostProcessor,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
<C> AsyncRabbitTemplate.RabbitConverterFuture<C> |
convertSendAndReceiveAsType(java.lang.String exchange,
java.lang.String routingKey,
java.lang.Object object,
org.springframework.core.ParameterizedTypeReference<C> responseType) |
java.lang.String |
getBeanName() |
ConnectionFactory |
getConnectionFactory() |
org.springframework.amqp.support.converter.MessageConverter |
getMessageConverter() |
int |
getPhase() |
RabbitTemplate |
getRabbitTemplate()
Return the underlying
RabbitTemplate used for sending. |
boolean |
isAutoStartup() |
boolean |
isRunning() |
void |
onMessage(org.springframework.amqp.core.Message message,
com.rabbitmq.client.Channel channel)
Callback for processing a received Rabbit message.
|
void |
returnedMessage(org.springframework.amqp.core.Message message,
int replyCode,
java.lang.String replyText,
java.lang.String exchange,
java.lang.String routingKey)
Returned message callback.
|
AsyncRabbitTemplate.RabbitMessageFuture |
sendAndReceive(org.springframework.amqp.core.Message message) |
AsyncRabbitTemplate.RabbitMessageFuture |
sendAndReceive(java.lang.String routingKey,
org.springframework.amqp.core.Message message) |
AsyncRabbitTemplate.RabbitMessageFuture |
sendAndReceive(java.lang.String exchange,
java.lang.String routingKey,
org.springframework.amqp.core.Message message) |
void |
setAutoStartup(boolean autoStartup) |
void |
setBeanName(java.lang.String beanName) |
void |
setEnableConfirms(boolean enableConfirms)
Set to true to enable publisher confirms.
|
void |
setMandatory(boolean mandatory)
Set to true to enable the receipt of returned messages that cannot be delivered
in the form of a
AmqpMessageReturnedException. |
void |
setMandatoryExpression(org.springframework.expression.Expression mandatoryExpression) |
void |
setMandatoryExpressionString(java.lang.String mandatoryExpression) |
void |
setPhase(int phase) |
void |
setReceiveTimeout(long receiveTimeout)
Set the receive timeout - the future returned by the send and receive
methods will be canceled when this timeout expires.
|
void |
setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
Set the task scheduler to expire timed out futures.
|
void |
start() |
void |
stop() |
void |
stop(java.lang.Runnable callback) |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitonMessagepublic static final int DEFAULT_RECEIVE_TIMEOUT
public AsyncRabbitTemplate(ConnectionFactory connectionFactory, java.lang.String exchange, java.lang.String routingKey, java.lang.String replyQueue)
connectionFactory - the connection factory.exchange - the default exchange to which requests will be sent.routingKey - the default routing key.replyQueue - the name of the reply queue to listen for replies.public AsyncRabbitTemplate(ConnectionFactory connectionFactory, java.lang.String exchange, java.lang.String routingKey, java.lang.String replyQueue, java.lang.String replyAddress)
connectionFactory - the connection factory.exchange - the default exchange to which requests will be sent.routingKey - the default routing key.replyQueue - the name of the reply queue to listen for replies.replyAddress - the reply address (exchange/routingKey).public AsyncRabbitTemplate(RabbitTemplate template, AbstractMessageListenerContainer container)
template - a RabbitTemplatecontainer - a AbstractMessageListenerContainer.public AsyncRabbitTemplate(RabbitTemplate template, AbstractMessageListenerContainer container, java.lang.String replyAddress)
template - a RabbitTemplate.container - a AbstractMessageListenerContainer.replyAddress - the reply address.public AsyncRabbitTemplate(ConnectionFactory connectionFactory, java.lang.String exchange, java.lang.String routingKey)
connectionFactory - the connection factory.exchange - the default exchange to which requests will be sent.routingKey - the default routing key.public AsyncRabbitTemplate(RabbitTemplate template)
template - a RabbitTemplatepublic void setAutoStartup(boolean autoStartup)
autoStartup - true for auto start.isAutoStartup()public void setPhase(int phase)
phase - the phase.getPhase()public void setMandatory(boolean mandatory)
AmqpMessageReturnedException.mandatory - true to enable returns.public void setMandatoryExpression(org.springframework.expression.Expression mandatoryExpression)
mandatoryExpression - a SpEL Expression to evaluate against each request
message. The result of the evaluation must be a boolean value.public void setMandatoryExpressionString(java.lang.String mandatoryExpression)
mandatoryExpression - a SpEL Expression to evaluate against each request
message. The result of the evaluation must be a boolean value.public void setEnableConfirms(boolean enableConfirms)
AsyncRabbitTemplate.RabbitFuture
returned by the send and receive operation will have a
ListenableFuture<Boolean> in its confirm property.enableConfirms - true to enable publisher confirms.public java.lang.String getBeanName()
public void setBeanName(java.lang.String beanName)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic ConnectionFactory getConnectionFactory()
RabbitTemplate.public void setReceiveTimeout(long receiveTimeout)
<= 0 means
futures never expire. Beware that this will cause a memory leak if a
reply is not received. Default: 30000 (30 seconds).receiveTimeout - the timeout in milliseconds.public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
taskScheduler - the task schedulersetReceiveTimeout(long)public org.springframework.amqp.support.converter.MessageConverter getMessageConverter()
RabbitTemplate's
MessageConverter.public RabbitTemplate getRabbitTemplate()
RabbitTemplate used for sending.public AsyncRabbitTemplate.RabbitMessageFuture sendAndReceive(org.springframework.amqp.core.Message message)
sendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic AsyncRabbitTemplate.RabbitMessageFuture sendAndReceive(java.lang.String routingKey, org.springframework.amqp.core.Message message)
sendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic AsyncRabbitTemplate.RabbitMessageFuture sendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message)
sendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.Object object)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.String routingKey, java.lang.Object object)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.String routingKey, java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)
convertSendAndReceive in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.Object object, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object object, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic <C> AsyncRabbitTemplate.RabbitConverterFuture<C> convertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<C> responseType)
convertSendAndReceiveAsType in interface org.springframework.amqp.core.AsyncAmqpTemplatepublic void start()
start in interface org.springframework.context.Lifecyclepublic void stop()
stop in interface org.springframework.context.Lifecyclepublic boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclepublic int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclepublic boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void stop(java.lang.Runnable callback)
stop in interface org.springframework.context.SmartLifecyclepublic void onMessage(org.springframework.amqp.core.Message message,
com.rabbitmq.client.Channel channel)
ChannelAwareMessageListenerImplementors are supposed to process the given Message, typically sending reply messages through the given Session.
onMessage in interface ChannelAwareMessageListenermessage - the received AMQP message (never null)channel - the underlying Rabbit Channel (never null)public void returnedMessage(org.springframework.amqp.core.Message message,
int replyCode,
java.lang.String replyText,
java.lang.String exchange,
java.lang.String routingKey)
RabbitTemplate.ReturnCallbackreturnedMessage in interface RabbitTemplate.ReturnCallbackmessage - the returned message.replyCode - the reply code.replyText - the reply text.exchange - the exchange.routingKey - the routing key.public void confirm(@NonNull
CorrelationData correlationData,
boolean ack,
@Nullable
java.lang.String cause)
RabbitTemplate.ConfirmCallbackconfirm in interface RabbitTemplate.ConfirmCallbackcorrelationData - correlation data for the callback.ack - true for ack, false for nackcause - An optional cause, for nack, when available, otherwise null.public java.lang.String toString()
toString in class java.lang.Object