Skip to content

Commit

Permalink
spring-projectsGH-1473: Switch to CompletableFuture
Browse files Browse the repository at this point in the history
Resolves spring-projects#1473

Given the stability of the project, it was simplest to copy the `AsyncRabbitTemplate`
rather than adding a lot of conditional code.

**2.4.x only; I will submit a separate PR for main**
  • Loading branch information
garyrussell committed Jul 27, 2022
1 parent 37109ad commit fb90f6c
Show file tree
Hide file tree
Showing 21 changed files with 1,723 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.amqp.core;

import java.util.concurrent.CompletableFuture;

import org.springframework.core.ParameterizedTypeReference;

/**
* Classes implementing this interface can perform asynchronous send and
* receive operations using {@link CompletableFuture}s.
*
* @author Gary Russell
* @since 2.4.7
*
*/
public interface AsyncAmqpTemplate2 {

/**
* Send a message to the default exchange with the default routing key. If the message
* contains a correlationId property, it must be unique.
* @param message the message.
* @return the {@link CompletableFuture}.
*/
CompletableFuture<Message> sendAndReceive(Message message);

/**
* Send a message to the default exchange with the supplied routing key. If the message
* contains a correlationId property, it must be unique.
* @param routingKey the routing key.
* @param message the message.
* @return the {@link CompletableFuture}.
*/
CompletableFuture<Message> sendAndReceive(String routingKey, Message message);

/**
* Send a message to the supplied exchange and routing key. If the message
* contains a correlationId property, it must be unique.
* @param exchange the exchange.
* @param routingKey the routing key.
* @param message the message.
* @return the {@link CompletableFuture}.
*/
CompletableFuture<Message> sendAndReceive(String exchange, String routingKey, Message message);

/**
* Convert the object to a message and send it to the default exchange with the
* default routing key.
* @param object the object to convert.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(Object object);

/**
* Convert the object to a message and send it to the default exchange with the
* provided routing key.
* @param routingKey the routing key.
* @param object the object to convert.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(String routingKey, Object object);

/**
* Convert the object to a message and send it to the provided exchange and
* routing key.
* @param exchange the exchange.
* @param routingKey the routing key.
* @param object the object to convert.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object);

/**
* Convert the object to a message and send it to the default exchange with the
* default routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(Object object, MessagePostProcessor messagePostProcessor);

/**
* Convert the object to a message and send it to the default exchange with the
* provided routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param routingKey the routing key.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(String routingKey, Object object,
MessagePostProcessor messagePostProcessor);

/**
* Convert the object to a message and send it to the provided exchange and
* routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param exchange the exchange
* @param routingKey the routing key.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object,
MessagePostProcessor messagePostProcessor);

/**
* Convert the object to a message and send it to the default exchange with the
* default routing key.
* @param object the object to convert.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, ParameterizedTypeReference<C> responseType);

/**
* Convert the object to a message and send it to the default exchange with the
* provided routing key.
* @param routingKey the routing key.
* @param object the object to convert.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
ParameterizedTypeReference<C> responseType);

/**
* Convert the object to a message and send it to the provided exchange and
* routing key.
* @param exchange the exchange.
* @param routingKey the routing key.
* @param object the object to convert.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
ParameterizedTypeReference<C> responseType);

/**
* Convert the object to a message and send it to the default exchange with the
* default routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, MessagePostProcessor messagePostProcessor,
ParameterizedTypeReference<C> responseType);

/**
* Convert the object to a message and send it to the default exchange with the
* provided routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param routingKey the routing key.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<C> responseType);

/**
* Convert the object to a message and send it to the provided exchange and
* routing key after invoking the {@link MessagePostProcessor}.
* If the post processor adds a correlationId property, it must be unique.
* @param exchange the exchange
* @param routingKey the routing key.
* @param object the object to convert.
* @param messagePostProcessor the post processor.
* @param responseType the response type.
* @param <C> the expected result type.
* @return the {@link CompletableFuture}.
*/
<C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<C> responseType);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,7 +89,9 @@
* @author Artem Bilan
*
* @since 1.6
* @deprecated in favor of {@link AsyncRabbitTemplate2}.
*/
@Deprecated
public class AsyncRabbitTemplate implements AsyncAmqpTemplate, ChannelAwareMessageListener, ReturnsCallback,
ConfirmCallback, BeanNameAware, SmartLifecycle {

Expand Down
Loading

0 comments on commit fb90f6c

Please sign in to comment.