原理是采用timewhile 实现的,源码分析可以参考
https://blog.csdn.net/sinat_14840559/article/details/129266105
除了useDelayLevel 已经默认改为false
private boolean useDelayLevel = false;
官方示意代码在public class TimerMessageProducer
for (int i = 0; i < totalMessagesToSend; i++) {
Message message = new Message(TOPIC, ("Hello scheduled message " + i).getBytes(StandardCharsets.UTF_8));
// This message will be delivered to consumer 10 seconds later.
//message.setDelayTimeSec(10);
// The effect is the same as the above
// message.setDelayTimeMs(10_000L);
// Set the specific delivery time, and the effect is the same as the above
message.setDeliverTimeMs(System.currentTimeMillis() + 10_000L);
// Send the message
SendResult result = producer.send(message);
System.out.printf(result + "\n");
}
实际测试大部分都会提前几百毫秒发送消息。
ps:
message.getBornTimestamp() – 消息生成时间
message.getDeliverTimeMs()-- 消息触发时间,即delay设置的timestamp
可以使用以下代码验证文章来源:https://www.toymoban.com/news/detail-618082.html
consumer.registerMessageListener((MessageListenerConcurrently) (messages, context) -> {
for (MessageExt message : messages) {
// Print approximate delay time period
String body = new String(message.getBody());
System.out.printf("Receive message[msgId=%s %d ,%d ms later ]\n", body,
System.currentTimeMillis() - message.getBornTimestamp(),
System.currentTimeMillis() - message.getDeliverTimeMs() );
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
});
proxy 配置如下:文章来源地址https://www.toymoban.com/news/detail-618082.html
{
"rocketMQClusterName": "DefaultCluster",
"useDelayLevel":"false"
}
到了这里,关于rocketmq 5.13任意时间延迟消息的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!