Class RabbitAmqpTemplate
java.lang.Object
org.springframework.amqp.rabbitmq.client.RabbitAmqpTemplate
- All Implemented Interfaces:
org.springframework.amqp.core.AsyncAmqpTemplate, org.springframework.beans.factory.DisposableBean
public class RabbitAmqpTemplate
extends Object
implements org.springframework.amqp.core.AsyncAmqpTemplate, org.springframework.beans.factory.DisposableBean
The
AmqpTemplate for RabbitMQ AMQP 1.0 protocol support.
A Spring-friendly wrapper around Environment.connectionBuilder();- Since:
- 4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertAndSend(Object message) Publish a message from converted body to the default exchange and routing key (if any) (or queue) configured on this template.convertAndSend(Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) convertAndSend(String exchange, @Nullable String routingKey, Object message) convertAndSend(String exchange, @Nullable String routingKey, Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) convertAndSend(String queue, Object message) convertAndSend(String queue, Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) <C> CompletableFuture<C> convertSendAndReceive(Object object) <C> CompletableFuture<C> convertSendAndReceive(Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) <C> CompletableFuture<C> convertSendAndReceive(String exchange, @Nullable String routingKey, Object object) <C> CompletableFuture<C> convertSendAndReceive(String exchange, @Nullable String routingKey, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) <C> CompletableFuture<C> convertSendAndReceive(String queue, Object object) <C> CompletableFuture<C> convertSendAndReceive(String queue, Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) <C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) <C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) <C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, @Nullable String routingKey, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) <C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, @Nullable String routingKey, Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) <C> CompletableFuture<C> convertSendAndReceiveAsType(String queue, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) <C> CompletableFuture<C> convertSendAndReceiveAsType(String queue, Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) voiddestroy()com.rabbitmq.client.amqp.PublisherReturn thePublisherfor low-level AMQP operations.CompletableFuture<org.springframework.amqp.core.Message> receive()CompletableFuture<org.springframework.amqp.core.Message> Request a head message from the provided queue.receiveAndConvert(String queueName) <T> CompletableFuture<T> receiveAndConvert(String queueName, @Nullable org.springframework.core.ParameterizedTypeReference<T> type) Receive a message fromsetReceiveQueue(String)and convert its body to the expected type.<T> CompletableFuture<T> receiveAndConvert(@Nullable org.springframework.core.ParameterizedTypeReference<T> type) Receive a message fromsetReceiveQueue(String)and convert its body to the expected type.<R,S> CompletableFuture <Boolean> receiveAndReply(String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R, S> callback) <R,S> CompletableFuture <Boolean> receiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R, S> callback) Publish the message to the provided queue.send(org.springframework.amqp.core.Message message) Publish a message to the default exchange and routing key (if any) (or queue) configured on this template.CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(String exchange, @Nullable String routingKey, org.springframework.amqp.core.Message message) CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(String queue, org.springframework.amqp.core.Message message) CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(org.springframework.amqp.core.Message message) voidsetCompletionTimeout(Duration completionTimeout) Set a duration forCompletableFuture.orTimeout(long, TimeUnit)on returns.voidsetExchange(String exchange) Set a default exchange for publishing.voidsetListeners(com.rabbitmq.client.amqp.Resource.StateListener... listeners) voidsetMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter) Set a converter forconvertAndSend(Object)operations.voidsetPublishTimeout(Duration timeout) voidSet default queue for publishing.voidsetReceiveQueue(String queue) The name of the default queue to receive messages from when none is specified explicitly.voidsetReplyToQueue(String queue) The name of the default queue to receive replies from when none is specified explicitly.voidsetRoutingKey(String routingKey) Set a default routing key.
-
Constructor Details
-
RabbitAmqpTemplate
-
-
Method Details
-
setListeners
public void setListeners(com.rabbitmq.client.amqp.Resource.StateListener... listeners) -
setPublishTimeout
-
setCompletionTimeout
Set a duration forCompletableFuture.orTimeout(long, TimeUnit)on returns. There is noCompletableFutureAPI likeonTimeout()requested from theCompletableFuture.get(long, TimeUnit), but used in operations AMQP resources have to be closed eventually independently of theCompletableFuturefulfilment. Defaults to 1 minute.- Parameters:
completionTimeout- duration for future completions.
-
setExchange
Set a default exchange for publishing. Cannot be real default AMQP exchange. ThesetQueue(String)is recommended instead. Mutually exclusive withsetQueue(String).- Parameters:
exchange- the default exchange
-
setRoutingKey
Set a default routing key. Mutually exclusive withsetQueue(String).- Parameters:
routingKey- the default routing key.
-
setQueue
Set default queue for publishing. Mutually exclusive withsetExchange(String)andsetRoutingKey(String).- Parameters:
queue- the default queue.
-
setReceiveQueue
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 operation.
-
setReplyToQueue
The name of the default queue to receive replies from when none is specified explicitly.- Parameters:
queue- the default queue name to use for send-n-receive operation.
-
setMessageConverter
public void setMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter) Set a converter forconvertAndSend(Object)operations.- Parameters:
messageConverter- the converter.
-
getPublisher
public com.rabbitmq.client.amqp.Publisher getPublisher()Return thePublisherfor low-level AMQP operations.- Returns:
- the
Publisherfor low-level AMQP operations.
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
send
Publish a message to the default exchange and routing key (if any) (or queue) configured on this template.- Specified by:
sendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
message- to publish- Returns:
- the
CompletableFutureas an async result of the message publication.
-
send
Publish the message to the provided queue.- Specified by:
sendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
queue- to publishmessage- to publish- Returns:
- the
CompletableFutureas an async result of the message publication.
-
send
public CompletableFuture<Boolean> send(String exchange, @Nullable String routingKey, org.springframework.amqp.core.Message message) - Specified by:
sendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertAndSend
Publish a message from converted body to the default exchange and routing key (if any) (or queue) configured on this template.- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
message- to publish- Returns:
- the
CompletableFutureas an async result of the message publication.
-
convertAndSend
- Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertAndSend
public CompletableFuture<Boolean> convertAndSend(String exchange, @Nullable String routingKey, Object message) - Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertAndSend
public CompletableFuture<Boolean> convertAndSend(Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertAndSend
public CompletableFuture<Boolean> convertAndSend(String queue, Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertAndSend
public CompletableFuture<Boolean> convertAndSend(String exchange, @Nullable String routingKey, Object message, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertAndSendin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
receive
- Specified by:
receivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
receive
Request a head message from the provided queue. A returnedCompletableFuturetimeouts aftersetCompletionTimeout(Duration).- Specified by:
receivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
queueName- the queue to consume message from.- Returns:
- the future with a received message.
- See Also:
-
receiveAndConvert
- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
receiveAndConvert
- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
receiveAndConvert
public <T> CompletableFuture<T> receiveAndConvert(@Nullable org.springframework.core.ParameterizedTypeReference<T> type) Receive a message fromsetReceiveQueue(String)and convert its body to the expected type. ThesetMessageConverter(MessageConverter)must be an implementation ofSmartMessageConverter.- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
type- the type to covert received result.- Returns:
- the CompletableFuture with a result.
-
receiveAndConvert
public <T> CompletableFuture<T> receiveAndConvert(String queueName, @Nullable org.springframework.core.ParameterizedTypeReference<T> type) Receive a message fromsetReceiveQueue(String)and convert its body to the expected type. ThesetMessageConverter(MessageConverter)must be an implementation ofSmartMessageConverter.- Specified by:
receiveAndConvertin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate- Parameters:
queueName- the queue to consume message from.type- the type to covert received result.- Returns:
- the CompletableFuture with a result.
-
receiveAndReply
public <R,S> CompletableFuture<Boolean> receiveAndReply(org.springframework.amqp.core.ReceiveAndReplyCallback<R, S> callback) - Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
receiveAndReply
public <R,S> CompletableFuture<Boolean> receiveAndReply(String queueName, org.springframework.amqp.core.ReceiveAndReplyCallback<R, S> callback) - Specified by:
receiveAndReplyin interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
sendAndReceive
public CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(org.springframework.amqp.core.Message message) - Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
sendAndReceive
public CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(String exchange, @Nullable String routingKey, org.springframework.amqp.core.Message message) - Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
sendAndReceive
public CompletableFuture<org.springframework.amqp.core.Message> sendAndReceive(String queue, org.springframework.amqp.core.Message message) - Specified by:
sendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
- Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
public <C> CompletableFuture<C> convertSendAndReceive(String exchange, @Nullable String routingKey, Object object) - Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
public <C> CompletableFuture<C> convertSendAndReceive(Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
public <C> CompletableFuture<C> convertSendAndReceive(String queue, Object object, org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceive
public <C> CompletableFuture<C> convertSendAndReceive(String exchange, @Nullable String routingKey, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor) - Specified by:
convertSendAndReceivein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(String queue, Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, @Nullable String routingKey, Object object, org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(String queue, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-
convertSendAndReceiveAsType
public <C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, @Nullable String routingKey, Object object, @Nullable org.springframework.amqp.core.MessagePostProcessor messagePostProcessor, @Nullable org.springframework.core.ParameterizedTypeReference<C> responseType) - Specified by:
convertSendAndReceiveAsTypein interfaceorg.springframework.amqp.core.AsyncAmqpTemplate
-