Skip to content

Commit b03a0bc

Browse files
authored
GH-1473: Switch to CompletableFuture
Resolves #1473 * Deprecate `AsyncRabbitTemplate2`. * Copy implementation from `AsyncRabbitTemplate2` to `AsyncRabbitTemplate` * Fix other `ListenableFuture` usages.
1 parent 8becb89 commit b03a0bc

23 files changed

+592
-324
lines changed

spring-amqp/src/main/java/org/springframework/amqp/core/AsyncAmqpTemplate.java

+34-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
1616

1717
package org.springframework.amqp.core;
1818

19+
import java.util.concurrent.CompletableFuture;
20+
1921
import org.springframework.core.ParameterizedTypeReference;
20-
import org.springframework.util.concurrent.ListenableFuture;
2122

2223
/**
2324
* Classes implementing this interface can perform asynchronous send and
24-
* receive operations.
25+
* receive operations using {@link CompletableFuture}s.
2526
*
2627
* @author Gary Russell
2728
* @since 2.0
@@ -33,47 +34,47 @@ public interface AsyncAmqpTemplate {
3334
* Send a message to the default exchange with the default routing key. If the message
3435
* contains a correlationId property, it must be unique.
3536
* @param message the message.
36-
* @return the {@link ListenableFuture}.
37+
* @return the {@link CompletableFuture}.
3738
*/
38-
ListenableFuture<Message> sendAndReceive(Message message);
39+
CompletableFuture<Message> sendAndReceive(Message message);
3940

4041
/**
4142
* Send a message to the default exchange with the supplied routing key. If the message
4243
* contains a correlationId property, it must be unique.
4344
* @param routingKey the routing key.
4445
* @param message the message.
45-
* @return the {@link ListenableFuture}.
46+
* @return the {@link CompletableFuture}.
4647
*/
47-
ListenableFuture<Message> sendAndReceive(String routingKey, Message message);
48+
CompletableFuture<Message> sendAndReceive(String routingKey, Message message);
4849

4950
/**
5051
* Send a message to the supplied exchange and routing key. If the message
5152
* contains a correlationId property, it must be unique.
5253
* @param exchange the exchange.
5354
* @param routingKey the routing key.
5455
* @param message the message.
55-
* @return the {@link ListenableFuture}.
56+
* @return the {@link CompletableFuture}.
5657
*/
57-
ListenableFuture<Message> sendAndReceive(String exchange, String routingKey, Message message);
58+
CompletableFuture<Message> sendAndReceive(String exchange, String routingKey, Message message);
5859

5960
/**
6061
* Convert the object to a message and send it to the default exchange with the
6162
* default routing key.
6263
* @param object the object to convert.
6364
* @param <C> the expected result type.
64-
* @return the {@link ListenableFuture}.
65+
* @return the {@link CompletableFuture}.
6566
*/
66-
<C> ListenableFuture<C> convertSendAndReceive(Object object);
67+
<C> CompletableFuture<C> convertSendAndReceive(Object object);
6768

6869
/**
6970
* Convert the object to a message and send it to the default exchange with the
7071
* provided routing key.
7172
* @param routingKey the routing key.
7273
* @param object the object to convert.
7374
* @param <C> the expected result type.
74-
* @return the {@link ListenableFuture}.
75+
* @return the {@link CompletableFuture}.
7576
*/
76-
<C> ListenableFuture<C> convertSendAndReceive(String routingKey, Object object);
77+
<C> CompletableFuture<C> convertSendAndReceive(String routingKey, Object object);
7778

7879
/**
7980
* Convert the object to a message and send it to the provided exchange and
@@ -82,9 +83,9 @@ public interface AsyncAmqpTemplate {
8283
* @param routingKey the routing key.
8384
* @param object the object to convert.
8485
* @param <C> the expected result type.
85-
* @return the {@link ListenableFuture}.
86+
* @return the {@link CompletableFuture}.
8687
*/
87-
<C> ListenableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object);
88+
<C> CompletableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object);
8889

8990
/**
9091
* Convert the object to a message and send it to the default exchange with the
@@ -93,9 +94,9 @@ public interface AsyncAmqpTemplate {
9394
* @param object the object to convert.
9495
* @param messagePostProcessor the post processor.
9596
* @param <C> the expected result type.
96-
* @return the {@link ListenableFuture}.
97+
* @return the {@link CompletableFuture}.
9798
*/
98-
<C> ListenableFuture<C> convertSendAndReceive(Object object, MessagePostProcessor messagePostProcessor);
99+
<C> CompletableFuture<C> convertSendAndReceive(Object object, MessagePostProcessor messagePostProcessor);
99100

100101
/**
101102
* Convert the object to a message and send it to the default exchange with the
@@ -105,9 +106,9 @@ public interface AsyncAmqpTemplate {
105106
* @param object the object to convert.
106107
* @param messagePostProcessor the post processor.
107108
* @param <C> the expected result type.
108-
* @return the {@link ListenableFuture}.
109+
* @return the {@link CompletableFuture}.
109110
*/
110-
<C> ListenableFuture<C> convertSendAndReceive(String routingKey, Object object,
111+
<C> CompletableFuture<C> convertSendAndReceive(String routingKey, Object object,
111112
MessagePostProcessor messagePostProcessor);
112113

113114
/**
@@ -119,9 +120,9 @@ <C> ListenableFuture<C> convertSendAndReceive(String routingKey, Object object,
119120
* @param object the object to convert.
120121
* @param messagePostProcessor the post processor.
121122
* @param <C> the expected result type.
122-
* @return the {@link ListenableFuture}.
123+
* @return the {@link CompletableFuture}.
123124
*/
124-
<C> ListenableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object,
125+
<C> CompletableFuture<C> convertSendAndReceive(String exchange, String routingKey, Object object,
125126
MessagePostProcessor messagePostProcessor);
126127

127128
/**
@@ -130,9 +131,9 @@ <C> ListenableFuture<C> convertSendAndReceive(String exchange, String routingKey
130131
* @param object the object to convert.
131132
* @param responseType the response type.
132133
* @param <C> the expected result type.
133-
* @return the {@link ListenableFuture}.
134+
* @return the {@link CompletableFuture}.
134135
*/
135-
<C> ListenableFuture<C> convertSendAndReceiveAsType(Object object, ParameterizedTypeReference<C> responseType);
136+
<C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, ParameterizedTypeReference<C> responseType);
136137

137138
/**
138139
* Convert the object to a message and send it to the default exchange with the
@@ -141,9 +142,9 @@ <C> ListenableFuture<C> convertSendAndReceive(String exchange, String routingKey
141142
* @param object the object to convert.
142143
* @param responseType the response type.
143144
* @param <C> the expected result type.
144-
* @return the {@link ListenableFuture}.
145+
* @return the {@link CompletableFuture}.
145146
*/
146-
<C> ListenableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
147+
<C> CompletableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
147148
ParameterizedTypeReference<C> responseType);
148149

149150
/**
@@ -154,9 +155,9 @@ <C> ListenableFuture<C> convertSendAndReceiveAsType(String routingKey, Object ob
154155
* @param object the object to convert.
155156
* @param responseType the response type.
156157
* @param <C> the expected result type.
157-
* @return the {@link ListenableFuture}.
158+
* @return the {@link CompletableFuture}.
158159
*/
159-
<C> ListenableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
160+
<C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
160161
ParameterizedTypeReference<C> responseType);
161162

162163
/**
@@ -167,9 +168,9 @@ <C> ListenableFuture<C> convertSendAndReceiveAsType(String exchange, String rout
167168
* @param messagePostProcessor the post processor.
168169
* @param responseType the response type.
169170
* @param <C> the expected result type.
170-
* @return the {@link ListenableFuture}.
171+
* @return the {@link CompletableFuture}.
171172
*/
172-
<C> ListenableFuture<C> convertSendAndReceiveAsType(Object object, MessagePostProcessor messagePostProcessor,
173+
<C> CompletableFuture<C> convertSendAndReceiveAsType(Object object, MessagePostProcessor messagePostProcessor,
173174
ParameterizedTypeReference<C> responseType);
174175

175176
/**
@@ -181,9 +182,9 @@ <C> ListenableFuture<C> convertSendAndReceiveAsType(Object object, MessagePostPr
181182
* @param messagePostProcessor the post processor.
182183
* @param responseType the response type.
183184
* @param <C> the expected result type.
184-
* @return the {@link ListenableFuture}.
185+
* @return the {@link CompletableFuture}.
185186
*/
186-
<C> ListenableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
187+
<C> CompletableFuture<C> convertSendAndReceiveAsType(String routingKey, Object object,
187188
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<C> responseType);
188189

189190
/**
@@ -196,9 +197,9 @@ <C> ListenableFuture<C> convertSendAndReceiveAsType(String routingKey, Object ob
196197
* @param messagePostProcessor the post processor.
197198
* @param responseType the response type.
198199
* @param <C> the expected result type.
199-
* @return the {@link ListenableFuture}.
200+
* @return the {@link CompletableFuture}.
200201
*/
201-
<C> ListenableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
202+
<C> CompletableFuture<C> convertSendAndReceiveAsType(String exchange, String routingKey, Object object,
202203
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<C> responseType);
203204

204205
}

0 commit comments

Comments
 (0)