This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-spring.git


The following commit(s) were added to refs/heads/master by this push:
     new 11aa3af  [ISSUE #705] Fix future in async send not complete
11aa3af is described below

commit 11aa3afd2df2daa6e273e546cc28e34bc0a469f3
Author: qianye <wuxingcan....@alibaba-inc.com>
AuthorDate: Thu Feb 13 12:07:49 2025 +0800

    [ISSUE #705] Fix future in async send not complete
---
 .../rocketmq/client/core/RocketMQClientTemplate.java       | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java
 
b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java
index 046f3a3..25f94ca 100644
--- 
a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java
+++ 
b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java
@@ -315,14 +315,24 @@ public class RocketMQClientTemplate extends 
AbstractMessageSendingTemplate<Strin
             throw new IllegalArgumentException("`message` and 
`message.payload` cannot be null");
         }
         Producer grpcProducer = this.getProducer();
+        CompletableFuture<SendReceipt> future0;
         try {
             org.apache.rocketmq.client.apis.message.Message rocketMsg = 
this.createRocketMQMessage(destination, message, messageDelayTime, 
messageGroup);
-            future = grpcProducer.sendAsync(rocketMsg);
+            future0 = grpcProducer.sendAsync(rocketMsg);
+            if (null != future) {
+                future0.whenComplete((sendReceipt, throwable) -> {
+                    if (null != throwable) {
+                        future.completeExceptionally(throwable);
+                    } else {
+                        future.complete(sendReceipt);
+                    }
+                });
+            }
         } catch (Exception e) {
             log.error("send request message failed. destination:{}, message:{} 
", destination, message);
             throw new MessagingException(e.getMessage(), e);
         }
-        return future;
+        return future0;
     }
 
     public Pair<SendReceipt, Transaction> sendMessageInTransaction(String 
destination, Object payload) throws ClientException {

Reply via email to