You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2020/03/31 13:09:32 UTC
[rocketmq-spring] 02/06: Add Method:#syncSend(java.lang.String,
java.util.Collection) Fix the bug of BatchMessage syncSend
without timeout
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
commit 0927fe80107c8019b8c532d254079ec6579698d0
Author: GongZhengMe <79...@qq.com>
AuthorDate: Thu Mar 26 21:05:13 2020 +0800
Add Method:#syncSend(java.lang.String, java.util.Collection<T>)
Fix the bug of BatchMessage syncSend without timeout
---
.../rocketmq/spring/core/RocketMQTemplate.java | 27 +---------------------
1 file changed, 1 insertion(+), 26 deletions(-)
diff --git a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java
index 626b16f..70001f0 100644
--- a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java
+++ b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java
@@ -474,32 +474,7 @@ public class RocketMQTemplate extends AbstractMessageSendingTemplate<String> imp
* @return {@link SendResult}
*/
public <T extends Message> SendResult syncSend(String destination, Collection<T> messages) {
- if (Objects.isNull(messages) || messages.size() == 0) {
- log.error("syncSend with batch failed. destination:{}, messages is empty ", destination);
- throw new IllegalArgumentException("`messages` can not be empty");
- }
-
- try {
- long now = System.currentTimeMillis();
- Collection<org.apache.rocketmq.common.message.Message> rmqMsgs = new ArrayList<>();
- for (Message msg : messages) {
- if (Objects.isNull(msg) || Objects.isNull(msg.getPayload())) {
- log.warn("Found a message empty in the batch, skip it");
- continue;
- }
- rmqMsgs.add(this.createRocketMqMessage(destination, msg));
- }
-
- SendResult sendResult = producer.send(rmqMsgs);
- long costTime = System.currentTimeMillis() - now;
- if (log.isDebugEnabled()) {
- log.debug("send messages cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
- }
- return sendResult;
- } catch (Exception e) {
- log.error("syncSend with batch failed. destination:{}, messages.size:{} ", destination, messages.size());
- throw new MessagingException(e.getMessage(), e);
- }
+ return syncSend(destination,messages,producer.getSendMsgTimeout());
}
/**