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 ee21b1b [ISSUE #708] fix sending delay message error with delayTime=0 ee21b1b is described below commit ee21b1b6ef84baf82f909f77d52a91d768b07f5c Author: tiger lee <tiger...@apache.org> AuthorDate: Fri Mar 7 17:21:45 2025 +0800 [ISSUE #708] fix sending delay message error with delayTime=0 Co-authored-by: tiger <tigerwe...@tencent.com> --- .../rocketmq/spring/core/RocketMQTemplate.java | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 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 1c9910b..b4fba54 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 @@ -632,23 +632,27 @@ public class RocketMQTemplate extends AbstractMessageSendingTemplate<String> imp log.error("syncSend failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } + if (Objects.isNull(mode)) { + throw new IllegalArgumentException("`delay mode` can be null"); + } + if (delayTime <= 0) { + throw new IllegalArgumentException("`delayTime` should be greater than 0"); + } try { long now = System.currentTimeMillis(); org.apache.rocketmq.common.message.Message rocketMsg = this.createRocketMqMessage(destination, message); - if (delayTime > 0 && Objects.nonNull(mode)) { - switch (mode) { - case DELAY_SECONDS: - rocketMsg.setDelayTimeSec(delayTime); - break; - case DELAY_MILLISECONDS: - rocketMsg.setDelayTimeMs(delayTime); - break; - case DELIVER_TIME_MILLISECONDS: - rocketMsg.setDeliverTimeMs(delayTime); - break; - default: - log.warn("delay mode: {} not support", mode); - } + switch (mode) { + case DELAY_SECONDS: + rocketMsg.setDelayTimeSec(delayTime); + break; + case DELAY_MILLISECONDS: + rocketMsg.setDelayTimeMs(delayTime); + break; + case DELIVER_TIME_MILLISECONDS: + rocketMsg.setDeliverTimeMs(delayTime); + break; + default: + log.warn("delay mode: {} not support", mode); } SendResult sendResult = producer.send(rocketMsg, timeout); long costTime = System.currentTimeMillis() - now;