public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware, RabbitOperations, MessageListener, PublisherCallbackChannel.Listener
Helper class that simplifies synchronous RabbitMQ access (sending and receiving messages).
The default settings are for non-transactional messaging, which reduces the amount of data exchanged with the broker.
To use a new transaction for every send or receive set the channelTransacted
flag. To extend the transaction over multiple invocations (more efficient), you can use a Spring transaction to
bracket the calls (with channelTransacted=true as well).
The only mandatory property is the ConnectionFactory. There are
strategies available for converting messages to and from Java objects (
MessageConverter) and for converting message headers (known as message
properties in AMQP, see MessagePropertiesConverter
). The defaults probably do something sensible for typical use cases, as long as the message content-type is set
appropriately.
The "send" methods all have overloaded versions that allow you to explicitly target an exchange and a routing key, or you can set default values to be used in all send operations. The plain "receive" methods allow you to explicitly target a queue to receive from, or you can set a default value for the template that applies to all explicit receives. The convenience methods for send and receive use the sender defaults if no exchange or routing key is specified, but they always use a temporary queue for the receive leg, so the default queue is ignored.
| Modifier and Type | Class and Description |
|---|---|
static interface |
RabbitTemplate.ConfirmCallback |
static interface |
RabbitTemplate.ReturnCallback |
logger| Constructor and Description |
|---|
RabbitTemplate()
Convenient constructor for use with setter injection.
|
RabbitTemplate(ConnectionFactory connectionFactory)
Create a rabbit template with default strategies and settings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
convertAndSend(Object object)
Convert a Java object to an Amqp
Message and send it to a default exchange with a default routing key. |
void |
convertAndSend(Object message,
MessagePostProcessor messagePostProcessor)
Convert a Java object to an Amqp
Message and send it to a default exchange with a default routing key. |
void |
convertAndSend(String routingKey,
Object object)
Convert a Java object to an Amqp
Message and send it to a default exchange with a specific routing key. |
void |
convertAndSend(String routingKey,
Object object,
CorrelationData correlationData) |
void |
convertAndSend(String routingKey,
Object message,
MessagePostProcessor messagePostProcessor)
Convert a Java object to an Amqp
Message and send it to a default exchange with a specific routing key. |
void |
convertAndSend(String routingKey,
Object message,
MessagePostProcessor messagePostProcessor,
CorrelationData correlationData) |
void |
convertAndSend(String exchange,
String routingKey,
Object object)
Convert a Java object to an Amqp
Message and send it to a specific exchange with a specific routing key. |
void |
convertAndSend(String exchange,
String routingKey,
Object object,
CorrelationData correlationData) |
void |
convertAndSend(String exchange,
String routingKey,
Object message,
MessagePostProcessor messagePostProcessor)
Convert a Java object to an Amqp
Message and send it to a specific exchange with a specific routing key. |
void |
convertAndSend(String exchange,
String routingKey,
Object message,
MessagePostProcessor messagePostProcessor,
CorrelationData correlationData) |
protected Message |
convertMessageIfNecessary(Object object) |
Object |
convertSendAndReceive(Object message)
Basic RPC pattern with conversion.
|
Object |
convertSendAndReceive(Object message,
MessagePostProcessor messagePostProcessor)
Basic RPC pattern with conversion.
|
Object |
convertSendAndReceive(String routingKey,
Object message)
Basic RPC pattern with conversion.
|
Object |
convertSendAndReceive(String routingKey,
Object message,
MessagePostProcessor messagePostProcessor)
Basic RPC pattern with conversion.
|
Object |
convertSendAndReceive(String exchange,
String routingKey,
Object message)
Basic RPC pattern with conversion.
|
Object |
convertSendAndReceive(String exchange,
String routingKey,
Object message,
MessagePostProcessor messagePostProcessor)
Basic RPC pattern with conversion.
|
void |
correlationconvertAndSend(Object object,
CorrelationData correlationData)
Deprecated.
|
void |
correlationConvertAndSend(Object object,
CorrelationData correlationData) |
protected void |
doSend(com.rabbitmq.client.Channel channel,
String exchange,
String routingKey,
Message message,
CorrelationData correlationData)
Send the given message to the specified exchange.
|
protected Message |
doSendAndReceive(String exchange,
String routingKey,
Message message)
Send a message and wait for a reply.
|
protected Message |
doSendAndReceiveWithFixed(String exchange,
String routingKey,
Message message) |
protected Message |
doSendAndReceiveWithTemporary(String exchange,
String routingKey,
Message message) |
<T> T |
execute(ChannelCallback<T> action) |
MessageConverter |
getMessageConverter()
Return the message converter for this template.
|
Collection<CorrelationData> |
getUnconfirmed(long age)
Gets unconfirmed correlation data older than age and removes them.
|
String |
getUUID()
Returns the UUID used to identify this Listener for returns.
|
void |
handleConfirm(PendingConfirm pendingConfirm,
boolean ack)
Invoked by the channel when a confirm is received.
|
void |
handleReturn(int replyCode,
String replyText,
String exchange,
String routingKey,
com.rabbitmq.client.AMQP.BasicProperties properties,
byte[] body) |
protected void |
initDefaultStrategies()
Set up the default strategies.
|
protected boolean |
isChannelLocallyTransacted(com.rabbitmq.client.Channel channel)
Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this
template's Channel handling and not by an external transaction coordinator.
|
boolean |
isConfirmListener() |
boolean |
isReturnListener() |
void |
onMessage(Message message) |
Message |
receive()
Receive a message if there is one from a default queue.
|
Message |
receive(String queueName)
Receive a message if there is one from a specific queue.
|
Object |
receiveAndConvert()
Receive a message if there is one from a default queue and convert it to a Java object.
|
Object |
receiveAndConvert(String queueName)
Receive a message if there is one from a specific queue and convert it to a Java object.
|
<R,S> boolean |
receiveAndReply(ReceiveAndReplyCallback<R,S> callback)
Receive a message if there is one from a default queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from MessageProperties
or to default exchange and default routingKey. |
<R,S> boolean |
receiveAndReply(ReceiveAndReplyCallback<R,S> callback,
ReplyToAddressCallback<S> replyToAddressCallback)
Receive a message if there is one from a default queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from result of ReplyToAddressCallback. |
<R,S> boolean |
receiveAndReply(ReceiveAndReplyCallback<R,S> callback,
String exchange,
String routingKey)
Receive a message if there is one from default queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the provided exchange and routingKey. |
<R,S> boolean |
receiveAndReply(String queueName,
ReceiveAndReplyCallback<R,S> callback)
Receive a message if there is one from provided queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from MessageProperties
or to default exchange and default routingKey. |
<R,S> boolean |
receiveAndReply(String queueName,
ReceiveAndReplyCallback<R,S> callback,
ReplyToAddressCallback<S> replyToAddressCallback)
Receive a message if there is one from provided queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from result of ReplyToAddressCallback. |
<R,S> boolean |
receiveAndReply(String queueName,
ReceiveAndReplyCallback<R,S> callback,
String replyExchange,
String replyRoutingKey)
Receive a message if there is one from provided queue, invoke provided
ReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the provided exchange and routingKey. |
void |
removePendingConfirmsReference(com.rabbitmq.client.Channel channel,
SortedMap<Long,PendingConfirm> unconfirmed)
When called, this listener must remove all references to the
pending confirm map.
|
void |
send(Message message)
Send a message to a default exchange with a default routing key.
|
void |
send(String routingKey,
Message message)
Send a message to a default exchange with a specific routing key.
|
void |
send(String exchange,
String routingKey,
Message message)
Send a message to a specific exchange with a specific routing key.
|
void |
send(String exchange,
String routingKey,
Message message,
CorrelationData correlationData) |
Message |
sendAndReceive(Message message)
Basic RPC pattern.
|
Message |
sendAndReceive(String routingKey,
Message message)
Basic RPC pattern.
|
Message |
sendAndReceive(String exchange,
String routingKey,
Message message)
Basic RPC pattern.
|
void |
setAfterReceivePostProcessor(MessagePostProcessor... afterReceivePostProcessors)
Set a
MessagePostProcessor that will be invoked immediately after a Channel#basicGet()
and before any message conversion is performed. |
void |
setBeanFactory(BeanFactory beanFactory) |
void |
setBeforePublishPostProcessors(MessagePostProcessor... beforePublishPostProcessors)
Set
MessagePostProcessors that will be invoked immediately before invoking
Channel#basicPublish(), after all other processing, except creating the
AMQP.BasicProperties from MessageProperties. |
void |
setConfirmCallback(RabbitTemplate.ConfirmCallback confirmCallback) |
void |
setCorrelationKey(String correlationKey)
If set to 'correlationId' (default) the correlationId property
will be used; otherwise the supplied key will be used.
|
void |
setEncoding(String encoding)
The encoding to use when inter-converting between byte arrays and Strings in message properties.
|
void |
setExchange(String exchange)
The name of the default exchange to use for send operations when none is specified.
|
void |
setMandatory(boolean mandatory) |
void |
setMandatoryExpression(Expression mandatoryExpression) |
void |
setMessageConverter(MessageConverter messageConverter)
Set the message converter for this template.
|
void |
setMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter)
Set the
MessagePropertiesConverter for this template. |
void |
setQueue(String queue)
The name of the default queue to receive messages from when none is specified explicitly.
|
void |
setReceiveConnectionFactorySelectorExpression(Expression receiveConnectionFactorySelectorExpression)
A SpEL
Expression to evaluate
against each receive queueName, if the provided RabbitAccessor.getConnectionFactory()
is an instance of AbstractRoutingConnectionFactory. |
void |
setRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
Add a
RecoveryCallback which is used for the retryTemplate.execute. |
void |
setReplyQueue(Queue replyQueue)
A queue for replies; if not provided, a temporary exclusive, auto-delete queue will
be used for each reply, unless RabbitMQ supports 'amq.rabbitmq.reply-to' - see
http://www.rabbitmq.com/direct-reply-to.html
|
void |
setReplyTimeout(long replyTimeout)
Specify the timeout in milliseconds to be used when waiting for a reply Message when using one of the
sendAndReceive methods.
|
void |
setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
Add a
RetryTemplate which will be used for all rabbit operations. |
void |
setReturnCallback(RabbitTemplate.ReturnCallback returnCallback) |
void |
setRoutingKey(String routingKey)
The value of a default routing key to use for send operations when none is specified.
|
void |
setSendConnectionFactorySelectorExpression(Expression sendConnectionFactorySelectorExpression)
A SpEL
Expression to evaluate
against each request message, if the provided RabbitAccessor.getConnectionFactory()
is an instance of AbstractRoutingConnectionFactory. |
afterPropertiesSet, convertRabbitAccessException, createConnection, getChannel, getConnection, getConnectionFactory, getTransactionalResourceHolder, isChannelTransacted, setChannelTransacted, setConnectionFactorypublic RabbitTemplate()
public RabbitTemplate(ConnectionFactory connectionFactory)
connectionFactory - the connection factory to useprotected void initDefaultStrategies()
public void setExchange(String exchange)
""
which is the default exchange in the broker (per the AMQP specification).exchange - the exchange name to use for send operationspublic void setRoutingKey(String routingKey)
routingKey - the default routing key to use for send operationspublic void setQueue(String queue)
queue - the default queue name to use for receivepublic void setEncoding(String encoding)
encoding - the encoding to setpublic void setReplyQueue(Queue replyQueue)
replyQueue - the replyQueue to setpublic void setReplyTimeout(long replyTimeout)
DEFAULT_REPLY_TIMEOUT. A negative value
indicates an indefinite timeout. Not used in the plain receive methods because there is no blocking receive
operation defined in the protocol.replyTimeout - the reply timeout in millisecondssendAndReceive(String, String, Message),
convertSendAndReceive(String, String, Object)public void setMessageConverter(MessageConverter messageConverter)
The default converter is a SimpleMessageConverter, which is able to handle byte arrays, Strings, and Serializable Objects depending on the message content type header.
messageConverter - The message converter.convertAndSend(java.lang.Object),
receiveAndConvert(),
SimpleMessageConverterpublic void setMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter)
MessagePropertiesConverter for this template. This converter is used to convert between raw byte
content in the message headers and plain Java objects. In particular there are limitations when dealing with very
long string headers, which hopefully are rare in practice, but if you need to use long headers you might need to
inject a special converter here.messagePropertiesConverter - The message properties converter.public MessageConverter getMessageConverter()
ChannelCallback implementations.public void setConfirmCallback(RabbitTemplate.ConfirmCallback confirmCallback)
public void setReturnCallback(RabbitTemplate.ReturnCallback returnCallback)
public void setMandatory(boolean mandatory)
public void setMandatoryExpression(Expression mandatoryExpression)
mandatoryExpression - a SpEL Expression to evaluate against each request
message, if a returnCallback has been provided. The result of expression must be
a boolean value.public void setSendConnectionFactorySelectorExpression(Expression sendConnectionFactorySelectorExpression)
Expression to evaluate
against each request message, if the provided RabbitAccessor.getConnectionFactory()
is an instance of AbstractRoutingConnectionFactory.
The result of this expression is used as lookupKey to get the target
ConnectionFactory from AbstractRoutingConnectionFactory
directly.
If this expression is evaluated to null, we fallback to the normal
AbstractRoutingConnectionFactory logic.
If there is no target ConnectionFactory with the evaluated lookupKey,
we fallback to the normal AbstractRoutingConnectionFactory logic
only if its property lenientFallback == true.
This expression is used for send operations.
sendConnectionFactorySelectorExpression - a SpEL Expression to evaluatepublic void setReceiveConnectionFactorySelectorExpression(Expression receiveConnectionFactorySelectorExpression)
Expression to evaluate
against each receive queueName, if the provided RabbitAccessor.getConnectionFactory()
is an instance of AbstractRoutingConnectionFactory.
The result of this expression is used as lookupKey to get the target
ConnectionFactory from AbstractRoutingConnectionFactory
directly.
If this expression is evaluated to null, we fallback to the normal
AbstractRoutingConnectionFactory logic.
If there is no target ConnectionFactory with the evaluated lookupKey,
we fallback to the normal AbstractRoutingConnectionFactory logic
only if its property lenientFallback == true.
This expression is used for receive operations.
receiveConnectionFactorySelectorExpression - a SpEL Expression to evaluatepublic void setCorrelationKey(String correlationKey)
correlationKey - the correlationKey to setpublic void setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
RetryTemplate which will be used for all rabbit operations.retryTemplate - The retry template.public void setRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
RecoveryCallback which is used for the retryTemplate.execute.
If retryTemplate isn't provided recoveryCallback is ignored.
RecoveryCallback should produce result compatible with
execute(ChannelCallback, ConnectionFactory) return type.recoveryCallback - The retry recoveryCallback.public void setBeanFactory(BeanFactory beanFactory) throws BeansException
setBeanFactory in interface BeanFactoryAwareBeansExceptionpublic void setBeforePublishPostProcessors(MessagePostProcessor... beforePublishPostProcessors)
MessagePostProcessors that will be invoked immediately before invoking
Channel#basicPublish(), after all other processing, except creating the
AMQP.BasicProperties from MessageProperties. May be used for operations
such as compression. Processors are invoked in order, depending on PriorityOrder,
Order and finally unordered.beforePublishPostProcessors - the post processor.public void setAfterReceivePostProcessor(MessagePostProcessor... afterReceivePostProcessors)
MessagePostProcessor that will be invoked immediately after a Channel#basicGet()
and before any message conversion is performed.
May be used for operations such as decompression Processors are invoked in order,
depending on PriorityOrder, Order and finally unordered.afterReceivePostProcessors - the post processor.public Collection<CorrelationData> getUnconfirmed(long age)
age - in millisecondspublic void send(Message message) throws AmqpException
AmqpTemplatesend in interface AmqpTemplatemessage - a message to sendAmqpException - if there is a problempublic void send(String routingKey, Message message) throws AmqpException
AmqpTemplatesend in interface AmqpTemplateroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic void send(String exchange, String routingKey, Message message) throws AmqpException
AmqpTemplatesend in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic void send(String exchange, String routingKey, Message message, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void convertAndSend(Object object) throws AmqpException
AmqpTemplateMessage and send it to a default exchange with a default routing key.convertAndSend in interface AmqpTemplateobject - a message to sendAmqpException - if there is a problem@Deprecated public void correlationconvertAndSend(Object object, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void correlationConvertAndSend(Object object, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void convertAndSend(String routingKey, Object object) throws AmqpException
AmqpTemplateMessage and send it to a default exchange with a specific routing key.convertAndSend in interface AmqpTemplateroutingKey - the routing keyobject - a message to sendAmqpException - if there is a problempublic void convertAndSend(String routingKey, Object object, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void convertAndSend(String exchange, String routingKey, Object object) throws AmqpException
AmqpTemplateMessage and send it to a specific exchange with a specific routing key.convertAndSend in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keyobject - a message to sendAmqpException - if there is a problempublic void convertAndSend(String exchange, String routingKey, Object object, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void convertAndSend(Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateMessage and send it to a default exchange with a default routing key.convertAndSend in interface AmqpTemplatemessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problempublic void convertAndSend(String routingKey, Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateMessage and send it to a default exchange with a specific routing key.convertAndSend in interface AmqpTemplateroutingKey - the routing keymessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problempublic void convertAndSend(String routingKey, Object message, MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic void convertAndSend(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateMessage and send it to a specific exchange with a specific routing key.convertAndSend in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keymessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problempublic void convertAndSend(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws AmqpException
AmqpExceptionpublic Message receive() throws AmqpException
AmqpTemplatereceive in interface AmqpTemplateAmqpException - if there is a problempublic Message receive(String queueName)
AmqpTemplatereceive in interface AmqpTemplatequeueName - the name of the queue to pollpublic Object receiveAndConvert() throws AmqpException
AmqpTemplatereceiveAndConvert in interface AmqpTemplateAmqpException - if there is a problempublic Object receiveAndConvert(String queueName) throws AmqpException
AmqpTemplatereceiveAndConvert in interface AmqpTemplatequeueName - the name of the queue to pollAmqpException - if there is a problempublic <R,S> boolean receiveAndReply(ReceiveAndReplyCallback<R,S> callback) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from MessageProperties
or to default exchange and default routingKey.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.true, if message was receivedAmqpException - if there is a problempublic <R,S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R,S> callback) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from MessageProperties
or to default exchange and default routingKey.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.queueName - the queue name to receive a message.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.true, if message was received.AmqpException - if there is a problem.public <R,S> boolean receiveAndReply(ReceiveAndReplyCallback<R,S> callback, String exchange, String routingKey) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the provided exchange and routingKey.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.exchange - the exchange name to send reply message.routingKey - the routing key to send reply message.true, if message was received.AmqpException - if there is a problem.public <R,S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R,S> callback, String replyExchange, String replyRoutingKey) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the provided exchange and routingKey.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.queueName - the queue name to receive a message.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.replyExchange - the exchange name to send reply message.replyRoutingKey - the routing key to send reply message.true, if message was receivedAmqpException - if there is a problempublic <R,S> boolean receiveAndReply(ReceiveAndReplyCallback<R,S> callback, ReplyToAddressCallback<S> replyToAddressCallback) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from result of ReplyToAddressCallback.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.replyToAddressCallback - the callback to determine replyTo address at runtime.true, if message was received.AmqpException - if there is a problem.public <R,S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R,S> callback, ReplyToAddressCallback<S> replyToAddressCallback) throws AmqpException
AmqpTemplateReceiveAndReplyCallback
and send reply message, if the callback returns one,
to the replyTo Address
from result of ReplyToAddressCallback.receiveAndReply in interface AmqpTemplateR - The type of the request after conversion from the Message.S - The type of the response.queueName - the queue name to receive a message.callback - a user-provided ReceiveAndReplyCallback implementation to process received message
and return a reply message.replyToAddressCallback - the callback to determine replyTo address at runtime.true, if message was receivedAmqpException - if there is a problempublic Message sendAndReceive(Message message) throws AmqpException
AmqpTemplatesendAndReceive in interface AmqpTemplatemessage - a message to sendAmqpException - if there is a problempublic Message sendAndReceive(String routingKey, Message message) throws AmqpException
AmqpTemplatesendAndReceive in interface AmqpTemplateroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic Message sendAndReceive(String exchange, String routingKey, Message message) throws AmqpException
AmqpTemplatesendAndReceive in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic Object convertSendAndReceive(Object message) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplatemessage - a message to sendAmqpException - if there is a problempublic Object convertSendAndReceive(String routingKey, Object message) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplateroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic Object convertSendAndReceive(String exchange, String routingKey, Object message) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keymessage - a message to sendAmqpException - if there is a problempublic Object convertSendAndReceive(Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplatemessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problempublic Object convertSendAndReceive(String routingKey, Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplateroutingKey - the routing keymessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problempublic Object convertSendAndReceive(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor) throws AmqpException
AmqpTemplateconvertSendAndReceive in interface AmqpTemplateexchange - the name of the exchangeroutingKey - the routing keymessage - a message to sendmessagePostProcessor - a processor to apply to the message before it is sentAmqpException - if there is a problemprotected Message doSendAndReceive(String exchange, String routingKey, Message message)
exchange - the exchange nameroutingKey - the routing keymessage - the message to sendprotected Message doSendAndReceiveWithTemporary(String exchange, String routingKey, Message message)
protected Message doSendAndReceiveWithFixed(String exchange, String routingKey, Message message)
public <T> T execute(ChannelCallback<T> action)
execute in interface RabbitOperationsprotected void doSend(com.rabbitmq.client.Channel channel,
String exchange,
String routingKey,
Message message,
CorrelationData correlationData)
throws Exception
channel - The RabbitMQ Channel to operate within.exchange - The name of the RabbitMQ exchange to send to.routingKey - The routing key.message - The Message to send.correlationData - The correlation data.IOException - If thrown by RabbitMQ API methodsExceptionprotected boolean isChannelLocallyTransacted(com.rabbitmq.client.Channel channel)
channel - the Channel to checkConnectionFactoryUtils.isChannelTransactional(com.rabbitmq.client.Channel, org.springframework.amqp.rabbit.connection.ConnectionFactory),
RabbitAccessor.isChannelTransacted()public void handleConfirm(PendingConfirm pendingConfirm, boolean ack)
PublisherCallbackChannel.ListenerhandleConfirm in interface PublisherCallbackChannel.ListenerpendingConfirm - The pending confirmation, containing
correlation data.ack - true when 'ack', false when 'nack'.public void handleReturn(int replyCode,
String replyText,
String exchange,
String routingKey,
com.rabbitmq.client.AMQP.BasicProperties properties,
byte[] body)
throws IOException
handleReturn in interface PublisherCallbackChannel.ListenerIOExceptionpublic boolean isConfirmListener()
isConfirmListener in interface PublisherCallbackChannel.Listenerpublic boolean isReturnListener()
isReturnListener in interface PublisherCallbackChannel.Listenerpublic void removePendingConfirmsReference(com.rabbitmq.client.Channel channel,
SortedMap<Long,PendingConfirm> unconfirmed)
PublisherCallbackChannel.ListenerremovePendingConfirmsReference in interface PublisherCallbackChannel.Listenerchannel - The channel.unconfirmed - The pending confirm map.public String getUUID()
PublisherCallbackChannel.ListenergetUUID in interface PublisherCallbackChannel.Listenerpublic void onMessage(Message message)
onMessage in interface MessageListener