Skip to content

Commit 11aa3af

Browse files
authored
[ISSUE #705] Fix future in async send not complete
1 parent 1be808d commit 11aa3af

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,24 @@ public CompletableFuture<SendReceipt> asyncSend(String destination, Message<?> m
315315
throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
316316
}
317317
Producer grpcProducer = this.getProducer();
318+
CompletableFuture<SendReceipt> future0;
318319
try {
319320
org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, messageGroup);
320-
future = grpcProducer.sendAsync(rocketMsg);
321+
future0 = grpcProducer.sendAsync(rocketMsg);
322+
if (null != future) {
323+
future0.whenComplete((sendReceipt, throwable) -> {
324+
if (null != throwable) {
325+
future.completeExceptionally(throwable);
326+
} else {
327+
future.complete(sendReceipt);
328+
}
329+
});
330+
}
321331
} catch (Exception e) {
322332
log.error("send request message failed. destination:{}, message:{} ", destination, message);
323333
throw new MessagingException(e.getMessage(), e);
324334
}
325-
return future;
335+
return future0;
326336
}
327337

328338
public Pair<SendReceipt, Transaction> sendMessageInTransaction(String destination, Object payload) throws ClientException {

0 commit comments

Comments
 (0)