This is an automated email from the ASF dual-hosted git repository.
dinglei 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 8d8f3a1 Add syncSendDeliverTimeMills and syncSendDelayTimeMills API
for RocketMQ 5.0 timer message (#521)
8d8f3a1 is described below
commit 8d8f3a1e0c7bb35401545e4f0c6b2fef078370ba
Author: rongtong <[email protected]>
AuthorDate: Mon Jan 30 14:51:10 2023 +0800
Add syncSendDeliverTimeMills and syncSendDelayTimeMills API for RocketMQ
5.0 timer message (#521)
---
.../rocketmq/spring/core/RocketMQTemplate.java | 60 +++++++++++++++++++++-
1 file changed, 59 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 8b444e3..a196686 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
@@ -538,6 +538,7 @@ public class RocketMQTemplate extends
AbstractMessageSendingTemplate<String> imp
/**
* Same to {@link #syncSend(String, Message)} with send delay time
specified in addition.
+ * This function is only valid when the broker version is 5.0 or above
*
* @param destination formats: `topicName:tags`
* @param message {@link org.springframework.messaging.Message}
@@ -550,6 +551,7 @@ public class RocketMQTemplate extends
AbstractMessageSendingTemplate<String> imp
/**
* Same to {@link #syncSend(String, Object)} with send delayTime specified
in addition.
+ * This function is only valid when the broker version is 5.0 or above
*
* @param destination formats: `topicName:tags`
* @param payload the Object to use as payload
@@ -561,8 +563,64 @@ public class RocketMQTemplate extends
AbstractMessageSendingTemplate<String> imp
return syncSend(destination, message, producer.getSendMsgTimeout(),
delayTime, DelayMode.DELAY_SECONDS);
}
+ /**
+ * Same to {@link #syncSend(String, Message)} with send delay time
specified in addition.
+ * This function is only valid when the broker version is 5.0 or above
+ *
+ * @param destination formats: `topicName:tags`
+ * @param message {@link org.springframework.messaging.Message}
+ * @param delayTime delay time in millisecond for message
+ * @return {@link SendResult}
+ */
+ public SendResult syncSendDelayTimeMills(String destination, Message<?>
message, long delayTime) {
+ return syncSend(destination, message, producer.getSendMsgTimeout(),
delayTime, DelayMode.DELAY_MILLISECONDS);
+ }
+
+ /**
+ * Same to {@link #syncSend(String, Object)} with send delayTime specified
in addition.
+ * This function is only valid when the broker version is 5.0 or above
+ *
+ * @param destination formats: `topicName:tags`
+ * @param payload the Object to use as payload
+ * @param delayTime delay time in millisecond for message
+ * @return {@link SendResult}
+ */
+ public SendResult syncSendDelayTimeMills(String destination, Object
payload, long delayTime) {
+ Message<?> message = MessageBuilder.withPayload(payload).build();
+ return syncSend(destination, message, producer.getSendMsgTimeout(),
delayTime, DelayMode.DELAY_MILLISECONDS);
+ }
+
+
+ /**
+ * Same to {@link #syncSend(String, Message)} with send in a delivered
time.
+ * This function is only valid when the broker version is 5.0 or above
+ *
+ * @param destination formats: `topicName:tags`
+ * @param message {@link org.springframework.messaging.Message}
+ * @param deliverTimeMills delivered time in millisecond for message
+ * @return {@link SendResult}
+ */
+ public SendResult syncSendDeliverTimeMills(String destination, Message<?>
message, long deliverTimeMills) {
+ return syncSend(destination, message, producer.getSendMsgTimeout(),
deliverTimeMills, DelayMode.DELIVER_TIME_MILLISECONDS);
+ }
+
+ /**
+ * Same to {@link #syncSend(String, Object)} with send in a delivered time.
+ * This function is only valid when the broker version is 5.0 or above
+ *
+ * @param destination formats: `topicName:tags`
+ * @param payload the Object to use as payload
+ * @param deliverTimeMills delivered time in millisecond for message
+ * @return {@link SendResult}
+ */
+ public SendResult syncSendDeliverTimeMills(String destination, Object
payload, long deliverTimeMills) {
+ Message<?> message = MessageBuilder.withPayload(payload).build();
+ return syncSend(destination, message, producer.getSendMsgTimeout(),
deliverTimeMills, DelayMode.DELIVER_TIME_MILLISECONDS);
+ }
+
/**
* Same to {@link #syncSend(String, Message)} with send timeout and delay
time specified in addition.
+ * This function is only valid when the broker version is 5.0 or above
*
* @param destination formats: `topicName:tags`
* @param message {@link org.springframework.messaging.Message}
@@ -570,7 +628,7 @@ public class RocketMQTemplate extends
AbstractMessageSendingTemplate<String> imp
* @param delayTime delay time for message
* @return {@link SendResult}
*/
- public SendResult syncSend(String destination, Message<?> message, long
timeout, long delayTime, DelayMode mode) {
+ private SendResult syncSend(String destination, Message<?> message, long
timeout, long delayTime, DelayMode mode) {
if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
log.error("syncSend failed. destination:{}, message is null ",
destination);
throw new IllegalArgumentException("`message` and
`message.payload` cannot be null");