消息发送部分几乎和之前一样,只是多加一了个 headerPROPERTY_DELAY_TIME_LEVEL, 这里我写的是 2,即延迟 5 秒。 Map<String, Object> headers = Maps.newHashMapWithExpectedSize(16); headers.put(MessageConst.PROPERTY_DELAY_TIME_LEVEL, 2); headers.put(MessageConst.PROPERTY_TAGS, "test03"); Order orde...
}// ignore DelayTimeLevel parameterif(msg.getDelayTimeLevel() !=0) { MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_DELAY_TIME_LEVEL); }// 检查消息内容Validators.checkMessage(msg,this.defaultMQProducer);SendResultsendResult=null;// 标识当前消息为事务消息MessageAccessor.putProperty(msg, Me...
Stringt=propertiesMap.get(MessageConst.PROPERTY_DELAY_TIME_LEVEL); if(TopicValidator.RMQ_SYS_SCHEDULE_TOPIC.equals(topic)&&t!=null) { intdelayLevel=Integer.parseInt(t); if(delayLevel>this.defaultMessageStore.getScheduleMessageService().getMaxDelayLevel()) { delayLevel=this.defaultMessageStore.getS...
long deliveryTimestampMs = Timestamps.toMillis(deliveryTimestamp); validateDelayTime(deliveryTimestampMs); //... String timestampString = String.valueOf(deliveryTimestampMs); //MessageConst.PROPERTY_TIMER_DELIVER_MS="TIMER_DELIVER_MS" MessageAccessor.putProperty(messageWithHeader, MessageConst.PROPERT...
上面的代码构中,Producer 创建消息时给消息传了一个系统属性 deliveryTimestamp,这个属性指定了消息投递的时间,并且封装到消息的 TIMER_DELIVER_MS 属性,代码如下: 代码语言:javascript 复制 protectedvoidfillDelayMessageProperty(apache.rocketmq.v2.Message message,org.apache.rocketmq.common.message.Message messageWit...
failScheduleOffset), DELAY_FOR_A_WHILE); } 定时topic主题消息转原topic主题消息 private MessageExtBrokerInner messageTimeup(MessageExt msgExt) { ... 删除赋值代码 通过property属性完成原topic的存储提取与转换 MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL); msgInner...
MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_DELAY_TIME_LEVEL); } Validators.checkMessage(msg,this.defaultMQProducer);SendResultsendResult=null;// 设置属性,TRAN_MSG其值为true,表示为事务消息MessageAccessor.putProperty(msg, MessageConst.PROPERTY_TRANSACTION_PREPARED,"true");// 设置生产者组。
} topic = TopicValidator.RMQ_SYS_SCHEDULE_TOPIC;int queueId = ScheduleMessageService.delayLevel2QueueId(msg.getDelayTimeLevel());// Backup real topic, queueId MessageAccessor.putProperty(msg, MessageConst.PROPERTY_REAL_TOPIC, msg.getTopic()); MessageAccessor.putProperty(msg, MessageConst.PROPERTY...
开源RocketMQ支持延迟消息,但是不支持秒级精度。默认支持18个level的延迟消息,这是通过broker端的messageDelayLevel配置项确定的,如下: messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h Broker在启动时,内部会创建一个内部主题:SCHEDULE_TOPIC_XXXX,根据延迟level的个数,创建...
delayLevelTable.entrySet()) { Integer level = entry.getKey(); Long timeDelay = entry.getValue(); Long offset = this.offsetTable.get(level); if (null == offset) { offset = 0L; } if (timeDelay != null) { this.timer.schedule(new DeliverDelayedMessageTimerTask(level, offset), FIRST...