in ons-sample/src/main/java/org/apache/rocketmq/ons/sample/producer/MQTimerProducer.java [29:52]
public static void main(String[] args) {
Properties producerProperties = new Properties();
producerProperties.setProperty(PropertyKeyConst.GROUP_ID, MQConfig.GROUP_ID);
producerProperties.setProperty(PropertyKeyConst.AccessKey, MQConfig.ACCESS_KEY);
producerProperties.setProperty(PropertyKeyConst.SecretKey, MQConfig.SECRET_KEY);
producerProperties.setProperty(PropertyKeyConst.NAMESRV_ADDR, MQConfig.NAMESRV_ADDR);
Producer producer = ONSFactory.createProducer(producerProperties);
producer.start();
System.out.printf("Producer Started. %n");
for (int i = 0; i < 10; i++) {
Message message = new Message(MQConfig.TOPIC, MQConfig.TAG, "MQ send timer message test".getBytes());
long delayTime = 3000;
message.setStartDeliverTime(System.currentTimeMillis() + delayTime);
try {
SendResult sendResult = producer.send(message);
assert sendResult != null;
System.out.printf("Send mq timer message success! Topic is: %s msgId is: %s%n", MQConfig.TOPIC, sendResult.getMessageId());
} catch (ONSClientException e) {
System.out.printf("Send mq message failed. Topic is: %s%n", MQConfig.TOPIC);
e.printStackTrace();
}
}
}