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

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

commit f09430aa5e3f52c007c7281ecf529f5ff00ee426
Author: rongtong <[email protected]>
AuthorDate: Tue Mar 31 21:11:57 2020 +0800

    Revert "Add Method:#syncSend(java.lang.String, java.util.Collection<T>) Fix 
the bug of BatchMessage syncSend without timeout"
    
    This reverts commit 0927fe80107c8019b8c532d254079ec6579698d0.
---
 .../rocketmq/spring/core/RocketMQTemplate.java     | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

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 70001f0..626b16f 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,7 +474,32 @@ public class RocketMQTemplate extends 
AbstractMessageSendingTemplate<String> imp
      * @return {@link SendResult}
      */
     public <T extends Message> SendResult syncSend(String destination, 
Collection<T> messages) {
-       return syncSend(destination,messages,producer.getSendMsgTimeout());
+        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);
+        }
     }
 
     /**

Reply via email to