Skip to content

Commit ee21b1b

Browse files
francisoliverleetiger
and
tiger
authored
[ISSUE #708] fix sending delay message error with delayTime=0
Co-authored-by: tiger <tigerweili@tencent.com>
1 parent 11aa3af commit ee21b1b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -632,23 +632,27 @@ private SendResult syncSend(String destination, Message<?> message, long timeout
632632
log.error("syncSend failed. destination:{}, message is null ", destination);
633633
throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
634634
}
635+
if (Objects.isNull(mode)) {
636+
throw new IllegalArgumentException("`delay mode` can be null");
637+
}
638+
if (delayTime <= 0) {
639+
throw new IllegalArgumentException("`delayTime` should be greater than 0");
640+
}
635641
try {
636642
long now = System.currentTimeMillis();
637643
org.apache.rocketmq.common.message.Message rocketMsg = this.createRocketMqMessage(destination, message);
638-
if (delayTime > 0 && Objects.nonNull(mode)) {
639-
switch (mode) {
640-
case DELAY_SECONDS:
641-
rocketMsg.setDelayTimeSec(delayTime);
642-
break;
643-
case DELAY_MILLISECONDS:
644-
rocketMsg.setDelayTimeMs(delayTime);
645-
break;
646-
case DELIVER_TIME_MILLISECONDS:
647-
rocketMsg.setDeliverTimeMs(delayTime);
648-
break;
649-
default:
650-
log.warn("delay mode: {} not support", mode);
651-
}
644+
switch (mode) {
645+
case DELAY_SECONDS:
646+
rocketMsg.setDelayTimeSec(delayTime);
647+
break;
648+
case DELAY_MILLISECONDS:
649+
rocketMsg.setDelayTimeMs(delayTime);
650+
break;
651+
case DELIVER_TIME_MILLISECONDS:
652+
rocketMsg.setDeliverTimeMs(delayTime);
653+
break;
654+
default:
655+
log.warn("delay mode: {} not support", mode);
652656
}
653657
SendResult sendResult = producer.send(rocketMsg, timeout);
654658
long costTime = System.currentTimeMillis() - now;

0 commit comments

Comments
 (0)