消息发送部分几乎和之前一样,只是多加一了个 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...
MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_DELAY_TIME_LEVEL); }// 检查消息内容Validators.checkMessage(msg,this.defaultMQProducer);SendResultsendResult=null;// 标识当前消息为事务消息MessageAccessor.putProperty(msg, MessageConst.PROPERTY_TRANSACTION_PREPARED,"true"); MessageAccessor.putProperty(...
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...
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");// 设置生产者组。...
if (msg.getDelayTimeLevel() != 0) { MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_DELAY_TIME_LEVEL); } Validators.checkMessage(msg, this.defaultMQProducer); SendResult sendResult = null; // todo 设置事务消息的标识 MessageAccessor.putProperty(msg, MessageConst.PROPERTY_TRANSACTION_PREPAR...
String t=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()) { ...
PROPERTY_DELAY_TIME_LEVEL); msgInner.setTopic(msgInner.getProperty(MessageConst.PROPERTY_REAL_TOPIC)); String queueIdStr = msgInner.getProperty(MessageConst.PROPERTY_REAL_QUEUE_ID); int queueId = Integer.parseInt(queueIdStr); msgInner.setQueueId(queueId); return msgInner; } } } 参考 ...
开源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的个数,创建...
if (msg.getDelayTimeLevel() != 0) { MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_DELAY_TIME_LEVEL); } Validators.checkMessage(msg, this.defaultMQProducer); SendResult sendResult = null; MessageAccessor.putProperty(msg, MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); ...
Producer 把消息发送到 Broker 后,Broker 判断到是延时消息,首先会把消息投递到延时队列(Topic = SCHEDULE_TOPIC_XXXX,queueId = delayTimeLevel - 1)。定时任务线程池会有 18 个线程来对延时队列进行调度,每个线程调度一个延时级别,调度任务把延时消息再投递到原始队列,这样 Consumer 就可以拉取到了。