Class RabbitTemplate
- java.lang.Object
-
- org.springframework.amqp.rabbit.connection.RabbitAccessor
-
- org.springframework.amqp.rabbit.core.RabbitTemplate
-
- All Implemented Interfaces:
org.springframework.amqp.core.AmqpTemplate,org.springframework.amqp.core.MessageListener,PublisherCallbackChannel.Listener,RabbitOperations,ChannelAwareMessageListener,ListenerContainerAware,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.Lifecycle
- Direct Known Subclasses:
BatchingRabbitTemplate
public class RabbitTemplate extends RabbitAccessor implements org.springframework.beans.factory.BeanFactoryAware, RabbitOperations, ChannelAwareMessageListener, ListenerContainerAware, PublisherCallbackChannel.Listener, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean
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
channelTransactedflag. To extend the transaction over multiple invocations (more efficient), you can use a Spring transaction to bracket the calls (withchannelTransacted=trueas 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, seeMessagePropertiesConverter). 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.
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRabbitTemplate.ConfirmCallbackA callback for publisher confirmations.static interfaceRabbitTemplate.ReturnCallbackDeprecated.in favor ofRabbitTemplate.ReturnCallback.returnedMessage(ReturnedMessage)which is easier to use with lambdas.static interfaceRabbitTemplate.ReturnsCallbackA callback for returned messages.protected static classRabbitTemplate.TemplateConsumerAddsRabbitTemplate.TemplateConsumer.toString()to theDefaultConsumer.-
Nested classes/interfaces inherited from interface org.springframework.amqp.rabbit.core.RabbitOperations
RabbitOperations.OperationsCallback<T>
-
-
Field Summary
-
Fields inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
logger
-
-
Constructor Summary
Constructors Constructor Description RabbitTemplate()Convenient constructor for use with setter injection.RabbitTemplate(ConnectionFactory connectionFactory)Create a rabbit template with default strategies and settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)AddMessagePostProcessorthat will be invoked immediately after aChannel#basicGet()and before any message conversion is performed.voidaddBeforePublishPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforePublishPostProcessors)AddMessagePostProcessorthat will be invoked immediately before invokingChannel#basicPublish(), after all other processing, except creating theAMQP.BasicPropertiesfromMessageProperties.voidaddListener(com.rabbitmq.client.Channel channel)Add this template as a confirms listener for the provided channel.voidconvertAndSend(java.lang.Object object)voidconvertAndSend(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)voidconvertAndSend(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a default exchange with a default routing key.voidconvertAndSend(java.lang.String routingKey, java.lang.Object object)voidconvertAndSend(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)voidconvertAndSend(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a default exchange with a specific routing key.voidconvertAndSend(java.lang.String routingKey, java.lang.Object object, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a default exchange with a specific routing key.voidconvertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object)voidconvertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)voidconvertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a specific exchange with a specific routing key.voidconvertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a specific exchange with a specific routing key.protected org.springframework.amqp.core.MessageconvertMessageIfNecessary(java.lang.Object object)java.lang.ObjectconvertSendAndReceive(java.lang.Object message)java.lang.ObjectconvertSendAndReceive(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)java.lang.ObjectconvertSendAndReceive(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Basic RPC pattern with conversion.java.lang.ObjectconvertSendAndReceive(java.lang.Object message, CorrelationData correlationData)Basic RPC pattern with conversion.java.lang.ObjectconvertSendAndReceive(java.lang.String routingKey, java.lang.Object message)java.lang.ObjectconvertSendAndReceive(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)java.lang.ObjectconvertSendAndReceive(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Basic RPC pattern with conversion.java.lang.ObjectconvertSendAndReceive(java.lang.String routingKey, java.lang.Object message, CorrelationData correlationData)Basic RPC pattern with conversion.java.lang.ObjectconvertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message)java.lang.ObjectconvertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor)java.lang.ObjectconvertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Basic RPC pattern with conversion.java.lang.ObjectconvertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, CorrelationData correlationData)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType)<T> TconvertSendAndReceiveAsType(java.lang.Object message, CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType)<T> TconvertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType)<T> TconvertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType)<T> TconvertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType)Basic RPC pattern with conversion.<T> TconvertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType)<T> TconvertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType)protected org.springframework.amqp.core.MessageconvertSendAndReceiveRaw(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData)Convert and send a message and return the raw reply message, or null.voidcorrelationConvertAndSend(java.lang.Object object, CorrelationData correlationData)Convert a Java object to an AmqpMessageand send it to a default exchange with a default routing key.voiddestroy()protected org.springframework.amqp.core.MessagedoReceiveNoWait(java.lang.String queueName)Non-blocking receive.voiddoSend(com.rabbitmq.client.Channel channel, java.lang.String exchangeArg, java.lang.String routingKeyArg, org.springframework.amqp.core.Message message, boolean mandatory, CorrelationData correlationData)Send the given message to the specified exchange.protected org.springframework.amqp.core.MessagedoSendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)Send a message and wait for a reply.protected org.springframework.amqp.core.MessagedoSendAndReceiveWithFixed(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)protected org.springframework.amqp.core.MessagedoSendAndReceiveWithTemporary(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)protected voiddoStart()Perform additional start actions.protected voiddoStop()Perform additional stop actions.<T> Texecute(ChannelCallback<T> action)Execute the callback with a channel and reliably close the channel afterwards.java.util.Collection<java.lang.String>expectedQueueNames()Invoked by the container during startup so it can verify the queue is correctly configured (if a simple reply queue name is used instead of exchange/routingKey).java.util.Collection<org.springframework.amqp.core.MessagePostProcessor>getAfterReceivePostProcessors()Return configured after receiveMessagePostProcessors ornull.java.lang.StringgetDefaultReceiveQueue()Return the configured default receive queue.java.lang.StringgetEncoding()The encoding used when converting between byte arrays and Strings in message properties.java.lang.StringgetExchange()org.springframework.amqp.support.converter.MessageConvertergetMessageConverter()Return the message converter for this template.protected MessagePropertiesConvertergetMessagePropertiesConverter()Return the properties converter.java.lang.StringgetRoutingKey()java.util.Collection<CorrelationData>getUnconfirmed(long age)Gets unconfirmed correlation data older than age and removes them.intgetUnconfirmedCount()Gets unconfirmed messages count.java.lang.StringgetUUID()Returns the UUID used to identify this Listener for returns.voidhandleConfirm(PendingConfirm pendingConfirm, boolean ack)Invoked by the channel when a confirm is received.voidhandleReturn(int replyCode, java.lang.String replyText, java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body)Handle a returned message.voidhandleReturn(com.rabbitmq.client.Return returned)Handle a returned message.protected voidinitDefaultStrategies()Set up the default strategies.<T> Tinvoke(RabbitOperations.OperationsCallback<T> action, com.rabbitmq.client.ConfirmCallback acks, com.rabbitmq.client.ConfirmCallback nacks)Invoke operations on the same channel.protected booleanisChannelLocallyTransacted(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.booleanisConfirmListener()java.lang.BooleanisMandatoryFor(org.springframework.amqp.core.Message message)Return whether the provided message should be sent with the mandatory flag set.booleanisReturnListener()booleanisRunning()booleanisUsePublisherConnection()True if separate publisher connection(s) are used.java.lang.StringnullSafeExchange(java.lang.String exchange)Return the exchange or the default exchange if null.java.lang.StringnullSafeRoutingKey(java.lang.String rk)Return the routing key or the default routing key if null.voidonMessage(org.springframework.amqp.core.Message message)Deprecated.- useonMessage(Message, Channel).voidonMessage(org.springframework.amqp.core.Message message, com.rabbitmq.client.Channel channel)Callback for processing a received Rabbit message.org.springframework.amqp.core.Messagereceive()org.springframework.amqp.core.Messagereceive(long timeoutMillis)org.springframework.amqp.core.Messagereceive(java.lang.String queueName)org.springframework.amqp.core.Messagereceive(java.lang.String queueName, long timeoutMillis)java.lang.ObjectreceiveAndConvert()java.lang.ObjectreceiveAndConvert(long timeoutMillis)<T> TreceiveAndConvert(long timeoutMillis, org.springframework.core.ParameterizedTypeReference<T> type)java.lang.ObjectreceiveAndConvert(java.lang.String queueName)java.lang.ObjectreceiveAndConvert(java.lang.String queueName, long timeoutMillis)<T> TreceiveAndConvert(java.lang.String queueName, long timeoutMillis, org.springframework.core.ParameterizedTypeReference<T> type)<T> TreceiveAndConvert(java.lang.String queueName, org.springframework.core.ParameterizedTypeReference<T> type)<T> TreceiveAndConvert(org.springframework.core.ParameterizedTypeReference<T> type)<R,S>
booleanreceiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback)<R,S>
booleanreceiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, java.lang.String replyExchange, java.lang.String replyRoutingKey)<R,S>
booleanreceiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, org.springframework.amqp.core.ReplyToAddressCallback<S> replyToAddressCallback)<R,S>
booleanreceiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback)<R,S>
booleanreceiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, java.lang.String exchange, java.lang.String routingKey)<R,S>
booleanreceiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, org.springframework.amqp.core.ReplyToAddressCallback<S> replyToAddressCallback)booleanremoveAfterReceivePostProcessor(org.springframework.amqp.core.MessagePostProcessor afterReceivePostProcessor)Remove the providedMessagePostProcessorfrom theafterReceivePostProcessorslist.booleanremoveBeforePublishPostProcessor(org.springframework.amqp.core.MessagePostProcessor beforePublishPostProcessor)Remove the providedMessagePostProcessorfrom thebeforePublishPostProcessorslist.protected voidreplyTimedOut(java.lang.String correlationId)Subclasses can implement this to be notified that a reply has timed out.voidrevoke(com.rabbitmq.client.Channel channel)When called, this listener should remove all references to the channel - it will no longer be invoked by the channel.voidsend(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message)voidsend(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)Send a message to a specific exchange with a specific routing key.voidsend(java.lang.String routingKey, org.springframework.amqp.core.Message message)voidsend(java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)Send a message to the default exchange with a specific routing key.voidsend(org.springframework.amqp.core.Message message)org.springframework.amqp.core.MessagesendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message)org.springframework.amqp.core.MessagesendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)org.springframework.amqp.core.MessagesendAndReceive(java.lang.String routingKey, org.springframework.amqp.core.Message message)org.springframework.amqp.core.MessagesendAndReceive(java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData)org.springframework.amqp.core.MessagesendAndReceive(org.springframework.amqp.core.Message message)org.springframework.amqp.core.MessagesendAndReceive(org.springframework.amqp.core.Message message, CorrelationData correlationData)protected voidsendToRabbit(com.rabbitmq.client.Channel channel, java.lang.String exchange, java.lang.String routingKey, boolean mandatory, org.springframework.amqp.core.Message message)voidsetAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)Set aMessagePostProcessorthat will be invoked immediately after aChannel#basicGet()and before any message conversion is performed.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)voidsetBeanName(java.lang.String name)voidsetBeforePublishPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforePublishPostProcessors)SetMessagePostProcessors that will be invoked immediately before invokingChannel#basicPublish(), after all other processing, except creating theAMQP.BasicPropertiesfromMessageProperties.voidsetConfirmCallback(RabbitTemplate.ConfirmCallback confirmCallback)voidsetConnectionFactory(ConnectionFactory connectionFactory)Set the ConnectionFactory to use for obtaining RabbitMQConnections.voidsetCorrelationDataPostProcessor(CorrelationDataPostProcessor correlationDataPostProcessor)Set aCorrelationDataPostProcessorto be invoked before publishing a message.voidsetCorrelationKey(java.lang.String correlationKey)If set to 'correlationId' (default) the correlationId property will be used; otherwise the supplied key will be used.voidsetDefaultReceiveQueue(java.lang.String queue)The name of the default queue to receive messages from when none is specified explicitly.voidsetEncoding(java.lang.String encoding)The encoding to use when converting between byte arrays and Strings in message properties.voidsetExchange(java.lang.String exchange)The name of the default exchange to use for send operations when none is specified.voidsetMandatory(boolean mandatory)Set the mandatory flag when sending messages; only applies if areturnCallbackhad been provided.voidsetMandatoryExpression(org.springframework.expression.Expression mandatoryExpression)voidsetMandatoryExpressionString(java.lang.String mandatoryExpression)voidsetMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter)Set the message converter for this template.voidsetMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter)Set theMessagePropertiesConverterfor this template.voidsetNoLocalReplyConsumer(boolean noLocalReplyConsumer)Set to true for a no-local consumer.voidsetReceiveConnectionFactorySelectorExpression(org.springframework.expression.Expression receiveConnectionFactorySelectorExpression)A SpELExpressionto evaluate against eachreceivequeueName, if the providedRabbitAccessor.getConnectionFactory()is an instance ofAbstractRoutingConnectionFactory.voidsetReceiveTimeout(long receiveTimeout)Specify the receive timeout in milliseconds when usingreceive()methods (forsendAndReceive()methods, refer toreplyTimeout.voidsetRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)Add aRecoveryCallbackwhich is used for theretryTemplate.execute.voidsetReplyAddress(java.lang.String replyAddress)An address 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 https://www.rabbitmq.com/direct-reply-to.htmlvoidsetReplyErrorHandler(org.springframework.util.ErrorHandler replyErrorHandler)When using a direct reply-to container for request/reply operations, set an error handler to be invoked when a reply delivery fails (e.g.voidsetReplyTimeout(long replyTimeout)Specify the timeout in milliseconds to be used when waiting for a reply Message when using one of the sendAndReceive methods.voidsetRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)Add aRetryTemplatewhich will be used for all rabbit operations.voidsetReturnCallback(RabbitTemplate.ReturnCallback returnCallback)Deprecated.in favor ofsetReturnsCallback(ReturnsCallback).voidsetReturnsCallback(RabbitTemplate.ReturnsCallback returnCallback)voidsetRoutingKey(java.lang.String routingKey)The value of a default routing key to use for send operations when none is specified.voidsetSendConnectionFactorySelectorExpression(org.springframework.expression.Expression sendConnectionFactorySelectorExpression)A SpELExpressionto evaluate against each request message, if the providedRabbitAccessor.getConnectionFactory()is an instance ofAbstractRoutingConnectionFactory.voidsetTaskExecutor(java.util.concurrent.Executor taskExecutor)Set a task executor to use when using aDirectReplyToMessageListenerContainer.voidsetUseChannelForCorrelation(boolean useChannelForCorrelation)When using direct reply-to, set this to true to avoid the server needing to send the correlation id in a reply header.voidsetUseDirectReplyToContainer(boolean useDirectReplyToContainer)Set whether or not to use aDirectReplyToMessageListenerContainerwhen direct reply-to is available and being used.voidsetUsePublisherConnection(boolean usePublisherConnection)To avoid deadlocked connections, it is generally recommended to use a separate connection for publishers and consumers (except when a publisher is participating in a consumer transaction).voidsetUserCorrelationId(boolean userCorrelationId)Set to true to use correlation id provided by the message instead of generating the correlation id for request/reply scenarios.voidsetUserIdExpression(org.springframework.expression.Expression userIdExpression)Set an expression to be evaluated to set the userId message property if it evaluates to a non-null value and the property is not already set in the message to be sent.voidsetUserIdExpressionString(java.lang.String userIdExpression)Set an expression to be evaluated to set the userId message property if it evaluates to a non-null value and the property is not already set in the message to be sent.voidsetUseTemporaryReplyQueues(boolean value)By default, when the broker supports it and noreplyAddressis provided, send/receive methods will use Direct reply-to (https://www.rabbitmq.com/direct-reply-to.html).voidstart()voidstop()protected booleanuseDirectReplyTo()Override this method use some other criteria to decide whether or not to use direct reply-to (https://www.rabbitmq.com/direct-reply-to.html).booleanwaitForConfirms(long timeout)Delegate to the underlying dedicated channel to wait for confirms.voidwaitForConfirmsOrDie(long timeout)Delegate to the underlying dedicated channel to wait for confirms.-
Methods inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
afterPropertiesSet, convertRabbitAccessException, createConnection, getChannel, getConnection, getConnectionFactory, getTransactionalResourceHolder, isChannelTransacted, setChannelTransacted
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
onMessageBatch
-
Methods inherited from interface org.springframework.amqp.core.MessageListener
containerAckMode, isAsyncReplies, onMessageBatch
-
Methods inherited from interface org.springframework.amqp.rabbit.core.RabbitOperations
convertSendAndReceiveAsType, getConnectionFactory, invoke
-
-
-
-
Constructor Detail
-
RabbitTemplate
public RabbitTemplate()
Convenient constructor for use with setter injection. Don't forget to set the connection factory.
-
RabbitTemplate
public RabbitTemplate(ConnectionFactory connectionFactory)
Create a rabbit template with default strategies and settings.- Parameters:
connectionFactory- the connection factory to use
-
-
Method Detail
-
initDefaultStrategies
protected void initDefaultStrategies()
Set up the default strategies. Subclasses can override if necessary.
-
setConnectionFactory
public final void setConnectionFactory(ConnectionFactory connectionFactory)
Description copied from class:RabbitAccessorSet the ConnectionFactory to use for obtaining RabbitMQConnections.- Overrides:
setConnectionFactoryin classRabbitAccessor- Parameters:
connectionFactory- The connection factory.
-
setExchange
public void setExchange(@Nullable java.lang.String exchange)The name of the default exchange to use for send operations when none is specified. Defaults to""which is the default exchange in the broker (per the AMQP specification).- Parameters:
exchange- the exchange name to use for send operations
-
getExchange
public java.lang.String getExchange()
- Returns:
- the name of the default exchange used by this template.
- Since:
- 1.6
-
setRoutingKey
public void setRoutingKey(java.lang.String routingKey)
The value of a default routing key to use for send operations when none is specified. Default is empty which is not helpful when using the default (or any direct) exchange, but fine if the exchange is a headers exchange for instance.- Parameters:
routingKey- the default routing key to use for send operations
-
getRoutingKey
public java.lang.String getRoutingKey()
- Returns:
- the default routing key used by this template.
- Since:
- 1.6
-
setDefaultReceiveQueue
public void setDefaultReceiveQueue(java.lang.String queue)
The name of the default queue to receive messages from when none is specified explicitly.- Parameters:
queue- the default queue name to use for receive- Since:
- 2.1.2
-
getDefaultReceiveQueue
@Nullable public java.lang.String getDefaultReceiveQueue()
Return the configured default receive queue.- Returns:
- the queue or null if not configured.
- Since:
- 2.2.22
-
setEncoding
public void setEncoding(java.lang.String encoding)
The encoding to use when converting between byte arrays and Strings in message properties.- Parameters:
encoding- the encoding to set
-
getEncoding
public java.lang.String getEncoding()
The encoding used when converting between byte arrays and Strings in message properties.- Returns:
- the encoding.
-
setReplyAddress
public void setReplyAddress(java.lang.String replyAddress)
An address 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 https://www.rabbitmq.com/direct-reply-to.htmlThe address can be a simple queue name (in which case the reply will be routed via the default exchange), or with the form
exchange/routingKeyto route the reply using an explicit exchange and routing key.- Parameters:
replyAddress- the replyAddress to set
-
setReceiveTimeout
public void setReceiveTimeout(long receiveTimeout)
Specify the receive timeout in milliseconds when usingreceive()methods (forsendAndReceive()methods, refer toreplyTimeout. By default, the value is zero, which means thereceive()methods will returnnullimmediately if there is no message available. Set to less than zero to wait for a message indefinitely.- Parameters:
receiveTimeout- the timeout.- Since:
- 1.5
-
setReplyTimeout
public 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. The default value is defined asDEFAULT_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.- Parameters:
replyTimeout- the reply timeout in milliseconds- See Also:
sendAndReceive(String, String, Message),convertSendAndReceive(String, String, Object)
-
setMessageConverter
public void setMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter)
Set the message converter for this template. Used to resolve Object parameters to convertAndSend methods and Object results from receiveAndConvert methods.The default converter is a SimpleMessageConverter, which is able to handle byte arrays, Strings, and Serializable Objects depending on the message content type header.
- Parameters:
messageConverter- The message converter.- See Also:
convertAndSend(java.lang.Object),receiveAndConvert(),SimpleMessageConverter
-
setMessagePropertiesConverter
public void setMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter)
Set theMessagePropertiesConverterfor 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.- Parameters:
messagePropertiesConverter- The message properties converter.
-
getMessagePropertiesConverter
protected MessagePropertiesConverter getMessagePropertiesConverter()
Return the properties converter.- Returns:
- the converter.
- Since:
- 2.0
-
getMessageConverter
public org.springframework.amqp.support.converter.MessageConverter getMessageConverter()
Return the message converter for this template. Useful for clients that want to take advantage of the converter inChannelCallbackimplementations.- Returns:
- The message converter.
-
setConfirmCallback
public void setConfirmCallback(RabbitTemplate.ConfirmCallback confirmCallback)
-
setReturnCallback
@Deprecated public void setReturnCallback(RabbitTemplate.ReturnCallback returnCallback)
Deprecated.in favor ofsetReturnsCallback(ReturnsCallback).Set a callback to receive returned messages.- Parameters:
returnCallback- the callback.
-
setReturnsCallback
public void setReturnsCallback(RabbitTemplate.ReturnsCallback returnCallback)
-
setMandatory
public void setMandatory(boolean mandatory)
Set the mandatory flag when sending messages; only applies if areturnCallbackhad been provided.- Parameters:
mandatory- the mandatory to set.
-
setMandatoryExpression
public void setMandatoryExpression(org.springframework.expression.Expression mandatoryExpression)
- Parameters:
mandatoryExpression- a SpELExpressionto evaluate against each request message, if areturnCallbackhas been provided. The result of the evaluation must be abooleanvalue.- Since:
- 1.4
-
setMandatoryExpressionString
public void setMandatoryExpressionString(java.lang.String mandatoryExpression)
- Parameters:
mandatoryExpression- a SpELExpressionto evaluate against each request message, if areturnCallbackhas been provided. The result of the evaluation must be abooleanvalue.- Since:
- 2.0
-
setSendConnectionFactorySelectorExpression
public void setSendConnectionFactorySelectorExpression(org.springframework.expression.Expression sendConnectionFactorySelectorExpression)
A SpELExpressionto evaluate against each request message, if the providedRabbitAccessor.getConnectionFactory()is an instance ofAbstractRoutingConnectionFactory.The result of this expression is used as
lookupKeyto get the targetConnectionFactoryfromAbstractRoutingConnectionFactorydirectly.If this expression is evaluated to
null, we fallback to the normalAbstractRoutingConnectionFactorylogic.If there is no target
ConnectionFactorywith the evaluatedlookupKey, we fallback to the normalAbstractRoutingConnectionFactorylogic only if its propertylenientFallback == true.This expression is used for
sendoperations.- Parameters:
sendConnectionFactorySelectorExpression- a SpELExpressionto evaluate- Since:
- 1.4
-
setReceiveConnectionFactorySelectorExpression
public void setReceiveConnectionFactorySelectorExpression(org.springframework.expression.Expression receiveConnectionFactorySelectorExpression)
A SpELExpressionto evaluate against eachreceivequeueName, if the providedRabbitAccessor.getConnectionFactory()is an instance ofAbstractRoutingConnectionFactory.The result of this expression is used as
lookupKeyto get the targetConnectionFactoryfromAbstractRoutingConnectionFactorydirectly.If this expression is evaluated to
null, we fallback to the normalAbstractRoutingConnectionFactorylogic.If there is no target
ConnectionFactorywith the evaluatedlookupKey, we fallback to the normalAbstractRoutingConnectionFactorylogic only if its propertylenientFallback == true.This expression is used for
receiveoperations.- Parameters:
receiveConnectionFactorySelectorExpression- a SpELExpressionto evaluate- Since:
- 1.4
-
setCorrelationKey
public void setCorrelationKey(java.lang.String correlationKey)
If set to 'correlationId' (default) the correlationId property will be used; otherwise the supplied key will be used.- Parameters:
correlationKey- the correlationKey to set
-
setRetryTemplate
public void setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
Add aRetryTemplatewhich will be used for all rabbit operations.- Parameters:
retryTemplate- The retry template.
-
setRecoveryCallback
public void setRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
Add aRecoveryCallbackwhich is used for theretryTemplate.execute. IfretryTemplateisn't providedrecoveryCallbackis ignored.RecoveryCallbackshould produce result compatible withexecute(ChannelCallback)return type.- Parameters:
recoveryCallback- The retry recoveryCallback.- Since:
- 1.4
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
setBeforePublishPostProcessors
public void setBeforePublishPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforePublishPostProcessors)
SetMessagePostProcessors that will be invoked immediately before invokingChannel#basicPublish(), after all other processing, except creating theAMQP.BasicPropertiesfromMessageProperties. May be used for operations such as compression. Processors are invoked in order, depending onPriorityOrder,Orderand finally unordered.- Parameters:
beforePublishPostProcessors- the post processor.- Since:
- 1.4.2
- See Also:
addBeforePublishPostProcessors(MessagePostProcessor...)
-
addBeforePublishPostProcessors
public void addBeforePublishPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforePublishPostProcessors)
AddMessagePostProcessorthat will be invoked immediately before invokingChannel#basicPublish(), after all other processing, except creating theAMQP.BasicPropertiesfromMessageProperties. May be used for operations such as compression. Processors are invoked in order, depending onPriorityOrder,Orderand finally unordered.In contrast to
setBeforePublishPostProcessors(MessagePostProcessor...), this method does not override the previously added beforePublishPostProcessors.- Parameters:
beforePublishPostProcessors- the post processor.- Since:
- 2.1.4
-
removeBeforePublishPostProcessor
public boolean removeBeforePublishPostProcessor(org.springframework.amqp.core.MessagePostProcessor beforePublishPostProcessor)
Remove the providedMessagePostProcessorfrom thebeforePublishPostProcessorslist.- Parameters:
beforePublishPostProcessor- the MessagePostProcessor to remove.- Returns:
- the boolean if the provided post processor has been removed.
- Since:
- 2.1.4
- See Also:
addBeforePublishPostProcessors(MessagePostProcessor...)
-
setAfterReceivePostProcessors
public void setAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)
Set aMessagePostProcessorthat will be invoked immediately after aChannel#basicGet()and before any message conversion is performed. May be used for operations such as decompression. Processors are invoked in order, depending onPriorityOrder,Orderand finally unordered.- Parameters:
afterReceivePostProcessors- the post processor.- Since:
- 1.5
- See Also:
addAfterReceivePostProcessors(MessagePostProcessor...)
-
getAfterReceivePostProcessors
@Nullable public java.util.Collection<org.springframework.amqp.core.MessagePostProcessor> getAfterReceivePostProcessors()
Return configured after receiveMessagePostProcessors ornull.- Returns:
- configured after receive
MessagePostProcessors ornull. - Since:
- 2.1.5
-
addAfterReceivePostProcessors
public void addAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)
AddMessagePostProcessorthat will be invoked immediately after aChannel#basicGet()and before any message conversion is performed. May be used for operations such as decompression. Processors are invoked in order, depending onPriorityOrder,Orderand finally unordered.In contrast to
setAfterReceivePostProcessors(MessagePostProcessor...), this method does not override the previously added afterReceivePostProcessors.- Parameters:
afterReceivePostProcessors- the post processor.- Since:
- 2.1.4
-
removeAfterReceivePostProcessor
public boolean removeAfterReceivePostProcessor(org.springframework.amqp.core.MessagePostProcessor afterReceivePostProcessor)
Remove the providedMessagePostProcessorfrom theafterReceivePostProcessorslist.- Parameters:
afterReceivePostProcessor- the MessagePostProcessor to remove.- Returns:
- the boolean if the provided post processor has been removed.
- Since:
- 2.1.4
- See Also:
addAfterReceivePostProcessors(MessagePostProcessor...)
-
setCorrelationDataPostProcessor
public void setCorrelationDataPostProcessor(CorrelationDataPostProcessor correlationDataPostProcessor)
Set aCorrelationDataPostProcessorto be invoked before publishing a message. Correlation data is used to correlate publisher confirms.- Parameters:
correlationDataPostProcessor- the post processor.- Since:
- 1.6.7
- See Also:
setConfirmCallback(ConfirmCallback)
-
setUseTemporaryReplyQueues
public void setUseTemporaryReplyQueues(boolean value)
By default, when the broker supports it and noreplyAddressis provided, send/receive methods will use Direct reply-to (https://www.rabbitmq.com/direct-reply-to.html). Setting this property to true will override that behavior and use a temporary, auto-delete, queue for each request instead. Changing this property has no effect once the first request has been processed.- Parameters:
value- true to use temporary queues.- Since:
- 1.6
-
setUseDirectReplyToContainer
public void setUseDirectReplyToContainer(boolean useDirectReplyToContainer)
Set whether or not to use aDirectReplyToMessageListenerContainerwhen direct reply-to is available and being used. When false, a new consumer is created for each request (the mechanism used in versions prior to 2.0). Default true.- Parameters:
useDirectReplyToContainer- set to false to use a consumer per request.- Since:
- 2.0
- See Also:
setUseTemporaryReplyQueues(boolean)
-
setUserIdExpression
public void setUserIdExpression(org.springframework.expression.Expression userIdExpression)
Set an expression to be evaluated to set the userId message property if it evaluates to a non-null value and the property is not already set in the message to be sent. See https://www.rabbitmq.com/validated-user-id.html- Parameters:
userIdExpression- the expression.- Since:
- 1.6
-
setUserIdExpressionString
public void setUserIdExpressionString(java.lang.String userIdExpression)
Set an expression to be evaluated to set the userId message property if it evaluates to a non-null value and the property is not already set in the message to be sent. See https://www.rabbitmq.com/validated-user-id.html- Parameters:
userIdExpression- the expression.- Since:
- 1.6
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setTaskExecutor
public void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
Set a task executor to use when using aDirectReplyToMessageListenerContainer.- Parameters:
taskExecutor- the executor.- Since:
- 2.0
-
setUserCorrelationId
public void setUserCorrelationId(boolean userCorrelationId)
Set to true to use correlation id provided by the message instead of generating the correlation id for request/reply scenarios. The correlation id must be unique for all in-process requests to avoid cross talk.Users must therefore take create care to ensure uniqueness.
- Parameters:
userCorrelationId- true to use user correlation data.
-
isUsePublisherConnection
public boolean isUsePublisherConnection()
True if separate publisher connection(s) are used.- Returns:
- true or false.
- Since:
- 2.0.2
- See Also:
setUsePublisherConnection(boolean)
-
setUsePublisherConnection
public void setUsePublisherConnection(boolean usePublisherConnection)
To avoid deadlocked connections, it is generally recommended to use a separate connection for publishers and consumers (except when a publisher is participating in a consumer transaction). Default 'false'. When setting this to true, be careful in that aRabbitAdminthat uses this template will declare queues on the publisher connection; this may not be what you expect, especially with exclusive queues that might be consumed in this application.- Parameters:
usePublisherConnection- true to use a publisher connection.- Since:
- 2.0.2
-
setNoLocalReplyConsumer
public void setNoLocalReplyConsumer(boolean noLocalReplyConsumer)
Set to true for a no-local consumer. Defaults to false.- Parameters:
noLocalReplyConsumer- true for a no-local consumer.- Since:
- 2.1
- See Also:
AbstractMessageListenerContainer.setNoLocal(boolean),Channel.basicConsume(String, boolean, String, boolean, boolean, Map, com.rabbitmq.client.Consumer)
-
setReplyErrorHandler
public void setReplyErrorHandler(org.springframework.util.ErrorHandler replyErrorHandler)
When using a direct reply-to container for request/reply operations, set an error handler to be invoked when a reply delivery fails (e.g. due to a late reply).- Parameters:
replyErrorHandler- the reply error handler- Since:
- 2.0.11
- See Also:
setUseDirectReplyToContainer(boolean)
-
setUseChannelForCorrelation
public void setUseChannelForCorrelation(boolean useChannelForCorrelation)
When using direct reply-to, set this to true to avoid the server needing to send the correlation id in a reply header. Use the channel to correlate the reply to a request instead.- Parameters:
useChannelForCorrelation- true to use the channel.- Since:
- 2.3.7
-
expectedQueueNames
@Nullable public java.util.Collection<java.lang.String> expectedQueueNames()
Invoked by the container during startup so it can verify the queue is correctly configured (if a simple reply queue name is used instead of exchange/routingKey).- Specified by:
expectedQueueNamesin interfaceListenerContainerAware- Returns:
- the queue name, if configured.
- Since:
- 1.5
-
getUnconfirmed
@Nullable public java.util.Collection<CorrelationData> getUnconfirmed(long age)
Gets unconfirmed correlation data older than age and removes them.- Parameters:
age- in milliseconds- Returns:
- the collection of correlation data for which confirms have not been received or null if no such confirms exist.
-
getUnconfirmedCount
public int getUnconfirmedCount()
Gets unconfirmed messages count.- Returns:
- The count of the messages that are not confirmed yet by RabbitMQ.
- Since:
- 2.0
-
start
public void start()
- Specified by:
startin interfaceorg.springframework.context.Lifecycle- Specified by:
startin interfaceRabbitOperations
-
doStart
protected void doStart()
Perform additional start actions.- Since:
- 2.0
-
stop
public void stop()
- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Specified by:
stopin interfaceRabbitOperations
-
doStop
protected void doStop()
Perform additional stop actions.- Since:
- 2.0
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle- Specified by:
isRunningin interfaceRabbitOperations
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
useDirectReplyTo
protected boolean useDirectReplyTo()
Override this method use some other criteria to decide whether or not to use direct reply-to (https://www.rabbitmq.com/direct-reply-to.html). The default implementation returns true if the broker supports it and there is noreplyAddressset anduseTemporaryReplyQueuesis false. When direct reply-to is not used, the template will create a temporary, exclusive, auto-delete queue for the reply.This method is invoked once only - when the first message is sent, from a synchronized block.
- Returns:
- true to use direct reply-to.
-
send
public void send(org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
send
public void send(java.lang.String routingKey, org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
send
public void send(java.lang.String routingKey, org.springframework.amqp.core.Message message, CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsSend a message to the default exchange with a specific routing key.- Specified by:
sendin interfaceRabbitOperations- Parameters:
routingKey- the routing keymessage- a message to sendcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
send
public void send(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
send
public void send(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsSend a message to a specific exchange with a specific routing key.- Specified by:
sendin interfaceRabbitOperations- Parameters:
exchange- the name of the exchangeroutingKey- the routing keymessage- a message to sendcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.Object object) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
correlationConvertAndSend
public void correlationConvertAndSend(java.lang.Object object, CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a default exchange with a default routing key.- Specified by:
correlationConvertAndSendin interfaceRabbitOperations- Parameters:
object- a message to sendcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.String routingKey, java.lang.Object object) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertAndSend
public void convertAndSend(java.lang.String routingKey, java.lang.Object object, CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a default exchange with a specific routing key.- Specified by:
convertAndSendin interfaceRabbitOperations- Parameters:
routingKey- the routing keyobject- a message to sendcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertAndSend
public void convertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object object, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a specific exchange with a specific routing key.- Specified by:
convertAndSendin interfaceRabbitOperations- Parameters:
exchange- the name of the exchangeroutingKey- the routing keyobject- a message to sendcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertAndSend
public void convertAndSend(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertAndSend
public void convertAndSend(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a default exchange with a default routing key.- Specified by:
convertAndSendin interfaceRabbitOperations- Parameters:
message- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a default exchange with a specific routing key.- Specified by:
convertAndSendin interfaceRabbitOperations- Parameters:
routingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertAndSend
public void convertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertAndSend
public void convertAndSend(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsConvert a Java object to an AmqpMessageand send it to a specific exchange with a specific routing key.- Specified by:
convertAndSendin interfaceRabbitOperations- Parameters:
exchange- the name of the exchangeroutingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
receive
@Nullable public org.springframework.amqp.core.Message receive() throws org.springframework.amqp.AmqpException- Specified by:
receivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receive
@Nullable public org.springframework.amqp.core.Message receive(java.lang.String queueName)
- Specified by:
receivein interfaceorg.springframework.amqp.core.AmqpTemplate
-
doReceiveNoWait
@Nullable protected org.springframework.amqp.core.Message doReceiveNoWait(java.lang.String queueName)
Non-blocking receive.- Parameters:
queueName- the queue to receive from.- Returns:
- The message, or null if none immediately available.
- Since:
- 1.5
-
receive
@Nullable public org.springframework.amqp.core.Message receive(long timeoutMillis) throws org.springframework.amqp.AmqpException- Specified by:
receivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receive
@Nullable public org.springframework.amqp.core.Message receive(java.lang.String queueName, long timeoutMillis)- Specified by:
receivein interfaceorg.springframework.amqp.core.AmqpTemplate
-
receiveAndConvert
@Nullable public java.lang.Object receiveAndConvert() throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public java.lang.Object receiveAndConvert(java.lang.String queueName) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public java.lang.Object receiveAndConvert(long timeoutMillis) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public java.lang.Object receiveAndConvert(java.lang.String queueName, long timeoutMillis) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(org.springframework.core.ParameterizedTypeReference<T> type) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(java.lang.String queueName, org.springframework.core.ParameterizedTypeReference<T> type) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(long timeoutMillis, org.springframework.core.ParameterizedTypeReference<T> type) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(java.lang.String queueName, long timeoutMillis, org.springframework.core.ParameterizedTypeReference<T> type) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, java.lang.String exchange, java.lang.String routingKey) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, java.lang.String replyExchange, java.lang.String replyRoutingKey) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, org.springframework.amqp.core.ReplyToAddressCallback<S> replyToAddressCallback) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
receiveAndReply
public <R,S> boolean receiveAndReply(java.lang.String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R,S> callback, org.springframework.amqp.core.ReplyToAddressCallback<S> replyToAddressCallback) throws org.springframework.amqp.AmqpException- Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpException- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(java.lang.String routingKey, org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpException- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message) throws org.springframework.amqp.AmqpException- Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
sendAndReceive
@Nullable public org.springframework.amqp.core.Message sendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpException- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.Object message) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.Object message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a default routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
message- a message to send.correlationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String routingKey, java.lang.Object message) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String routingKey, java.lang.Object message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
routingKey- the routing keymessage- a message to sendcorrelationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a specific exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
exchange- the name of the exchangeroutingKey- the routing keymessage- a message to sendcorrelationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a default routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
message- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
routingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceive
@Nullable public java.lang.Object convertSendAndReceive(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a specific exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.- Specified by:
convertSendAndReceivein interfaceRabbitOperations- Parameters:
exchange- the name of the exchangeroutingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.Object message, @Nullable CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a default routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout. Requires aSmartMessageConverter.- Specified by:
convertSendAndReceiveAsTypein interfaceRabbitOperations- Type Parameters:
T- the type.- Parameters:
message- a message to send.correlationData- data to correlate publisher confirms.responseType- the type to convert the reply to.- Returns:
- the response if there is one.
- Throws:
org.springframework.amqp.AmqpException- if there is a problem.
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, @Nullable CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout. Requires aSmartMessageConverter.- Specified by:
convertSendAndReceiveAsTypein interfaceRabbitOperations- Type Parameters:
T- the type.- Parameters:
routingKey- the routing keymessage- a message to sendcorrelationData- data to correlate publisher confirms.responseType- the type to convert the reply to.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a default routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout. Requires aSmartMessageConverter.- Specified by:
convertSendAndReceiveAsTypein interfaceRabbitOperations- Type Parameters:
T- the type.- Parameters:
message- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.responseType- the type to convert the reply to.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String routingKey, java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a default exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout. Requires aSmartMessageConverter.- Specified by:
convertSendAndReceiveAsTypein interfaceRabbitOperations- Type Parameters:
T- the type.- Parameters:
routingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.responseType- the type to convert the reply to.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpException- Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AmqpTemplate- Throws:
org.springframework.amqp.AmqpException
-
convertSendAndReceiveAsType
@Nullable public <T> T convertSendAndReceiveAsType(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.amqp.AmqpExceptionDescription copied from interface:RabbitOperationsBasic RPC pattern with conversion. Send a Java object converted to a message to a specific exchange with a specific routing key and attempt to receive a response, converting that to a Java object. Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout. Requires aSmartMessageConverter.- Specified by:
convertSendAndReceiveAsTypein interfaceRabbitOperations- Type Parameters:
T- the type.- Parameters:
exchange- the name of the exchangeroutingKey- the routing keymessage- a message to sendmessagePostProcessor- a processor to apply to the message before it is sentcorrelationData- data to correlate publisher confirms.responseType- the type to convert the reply to.- Returns:
- the response if there is one
- Throws:
org.springframework.amqp.AmqpException- if there is a problem
-
convertSendAndReceiveRaw
@Nullable protected org.springframework.amqp.core.Message convertSendAndReceiveRaw(java.lang.String exchange, java.lang.String routingKey, java.lang.Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable CorrelationData correlationData)Convert and send a message and return the raw reply message, or null. Subclasses can invoke this method if they want to perform conversion on the outbound message but have direct access to the reply message before conversion.- Parameters:
exchange- the exchange.routingKey- the routing key.message- the data to send.messagePostProcessor- a message post processor (can be null).correlationData- correlation data (can be null).- Returns:
- the reply message or null if a timeout occurs.
- Since:
- 1.6.6
-
convertMessageIfNecessary
protected org.springframework.amqp.core.Message convertMessageIfNecessary(java.lang.Object object)
-
doSendAndReceive
@Nullable protected org.springframework.amqp.core.Message doSendAndReceive(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData)Send a message and wait for a reply.- Parameters:
exchange- the exchange nameroutingKey- the routing keymessage- the message to sendcorrelationData- the correlation data for confirms- Returns:
- the message that is received in reply
-
doSendAndReceiveWithTemporary
@Nullable protected org.springframework.amqp.core.Message doSendAndReceiveWithTemporary(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData)
-
doSendAndReceiveWithFixed
@Nullable protected org.springframework.amqp.core.Message doSendAndReceiveWithFixed(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message, @Nullable CorrelationData correlationData)
-
replyTimedOut
protected void replyTimedOut(java.lang.String correlationId)
Subclasses can implement this to be notified that a reply has timed out.- Parameters:
correlationId- the correlationId- Since:
- 2.1.2
-
isMandatoryFor
public java.lang.Boolean isMandatoryFor(org.springframework.amqp.core.Message message)
Return whether the provided message should be sent with the mandatory flag set.- Parameters:
message- the message.- Returns:
- true for mandatory.
- Since:
- 2.0
-
execute
@Nullable public <T> T execute(ChannelCallback<T> action)
Description copied from interface:RabbitOperationsExecute the callback with a channel and reliably close the channel afterwards.- Specified by:
executein interfaceRabbitOperations- Type Parameters:
T- the return type.- Parameters:
action- the call back.- Returns:
- the result from the
ChannelCallback.doInRabbit(com.rabbitmq.client.Channel).
-
invoke
@Nullable public <T> T invoke(RabbitOperations.OperationsCallback<T> action, @Nullable com.rabbitmq.client.ConfirmCallback acks, @Nullable com.rabbitmq.client.ConfirmCallback nacks)
Description copied from interface:RabbitOperationsInvoke operations on the same channel. If callbacks are needed, both callbacks must be supplied.- Specified by:
invokein interfaceRabbitOperations- Type Parameters:
T- the return type.- Parameters:
action- the callback.acks- a confirm callback for acks.nacks- a confirm callback for nacks.- Returns:
- the result of the action method.
-
waitForConfirms
public boolean waitForConfirms(long timeout)
Description copied from interface:RabbitOperationsDelegate to the underlying dedicated channel to wait for confirms. The connection factory must be configured for publisher confirms and this method must be called within the scope of anRabbitOperations.invoke(OperationsCallback)operation. RequiresCachingConnectionFactory#setPublisherConfirms(true).- Specified by:
waitForConfirmsin interfaceRabbitOperations- Parameters:
timeout- the timeout- Returns:
- true if acks and no nacks are received.
- See Also:
Channel.waitForConfirms(long)
-
waitForConfirmsOrDie
public void waitForConfirmsOrDie(long timeout)
Description copied from interface:RabbitOperationsDelegate to the underlying dedicated channel to wait for confirms. The connection factory must be configured for publisher confirms and this method must be called within the scope of anRabbitOperations.invoke(OperationsCallback)operation. RequiresCachingConnectionFactory#setPublisherConfirms(true).- Specified by:
waitForConfirmsOrDiein interfaceRabbitOperations- Parameters:
timeout- the timeout- See Also:
Channel.waitForConfirmsOrDie(long)
-
doSend
public void doSend(com.rabbitmq.client.Channel channel, java.lang.String exchangeArg, java.lang.String routingKeyArg, org.springframework.amqp.core.Message message, boolean mandatory, @Nullable CorrelationData correlationData) throws java.io.IOExceptionSend the given message to the specified exchange.- Parameters:
channel- The RabbitMQ Channel to operate within.exchangeArg- The name of the RabbitMQ exchange to send to.routingKeyArg- The routing key.message- The Message to send.mandatory- The mandatory flag.correlationData- The correlation data.- Throws:
java.io.IOException- If thrown by RabbitMQ API methods.
-
nullSafeExchange
public java.lang.String nullSafeExchange(java.lang.String exchange)
Return the exchange or the default exchange if null.- Parameters:
exchange- the exchange.- Returns:
- the result.
- Since:
- 2.3.4
-
nullSafeRoutingKey
public java.lang.String nullSafeRoutingKey(java.lang.String rk)
Return the routing key or the default routing key if null.- Parameters:
rk- the routing key.- Returns:
- the result.
- Since:
- 2.3.4
-
sendToRabbit
protected void sendToRabbit(com.rabbitmq.client.Channel channel, java.lang.String exchange, java.lang.String routingKey, boolean mandatory, org.springframework.amqp.core.Message message) throws java.io.IOException- Throws:
java.io.IOException
-
isChannelLocallyTransacted
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.- Parameters:
channel- the Channel to check- Returns:
- whether the given Channel is locally transacted
- See Also:
ConnectionFactoryUtils.isChannelTransactional(com.rabbitmq.client.Channel, org.springframework.amqp.rabbit.connection.ConnectionFactory),RabbitAccessor.isChannelTransacted()
-
addListener
public void addListener(com.rabbitmq.client.Channel channel)
Add this template as a confirms listener for the provided channel.- Parameters:
channel- the channel.- Since:
- 2.0
-
handleConfirm
public void handleConfirm(PendingConfirm pendingConfirm, boolean ack)
Description copied from interface:PublisherCallbackChannel.ListenerInvoked by the channel when a confirm is received.- Specified by:
handleConfirmin interfacePublisherCallbackChannel.Listener- Parameters:
pendingConfirm- The pending confirmation, containing correlation data.ack- true when 'ack', false when 'nack'.
-
handleReturn
public void handleReturn(int replyCode, java.lang.String replyText, java.lang.String exchange, java.lang.String routingKey, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body)Description copied from interface:PublisherCallbackChannel.ListenerHandle a returned message.- Specified by:
handleReturnin interfacePublisherCallbackChannel.Listener- Parameters:
replyCode- the reply code.replyText- the reply text.exchange- the exchange.routingKey- the routing key.properties- the message properties.body- the message body.
-
handleReturn
public void handleReturn(com.rabbitmq.client.Return returned)
Description copied from interface:PublisherCallbackChannel.ListenerHandle a returned message.- Specified by:
handleReturnin interfacePublisherCallbackChannel.Listener- Parameters:
returned- the message and metadata.
-
isConfirmListener
public boolean isConfirmListener()
- Specified by:
isConfirmListenerin interfacePublisherCallbackChannel.Listener
-
isReturnListener
public boolean isReturnListener()
- Specified by:
isReturnListenerin interfacePublisherCallbackChannel.Listener
-
revoke
public void revoke(com.rabbitmq.client.Channel channel)
Description copied from interface:PublisherCallbackChannel.ListenerWhen called, this listener should remove all references to the channel - it will no longer be invoked by the channel.- Specified by:
revokein interfacePublisherCallbackChannel.Listener- Parameters:
channel- The channel.
-
getUUID
public java.lang.String getUUID()
Description copied from interface:PublisherCallbackChannel.ListenerReturns the UUID used to identify this Listener for returns.- Specified by:
getUUIDin interfacePublisherCallbackChannel.Listener- Returns:
- A string representation of the UUID.
-
onMessage
public void onMessage(org.springframework.amqp.core.Message message, @Nullable com.rabbitmq.client.Channel channel)Description copied from interface:ChannelAwareMessageListenerCallback for processing a received Rabbit message.Implementors are supposed to process the given Message, typically sending reply messages through the given Session.
- Specified by:
onMessagein interfaceChannelAwareMessageListener- Parameters:
message- the received AMQP message (nevernull)channel- the underlying Rabbit Channel (nevernullunless called by the stream listener container).
-
onMessage
@Deprecated public void onMessage(org.springframework.amqp.core.Message message)
Deprecated.- useonMessage(Message, Channel).- Specified by:
onMessagein interfaceChannelAwareMessageListener- Specified by:
onMessagein interfaceorg.springframework.amqp.core.MessageListener
-
-