创建-删除-修改定时器
更新时间:2019-06-14
创建定时器
请参考以下代码创建规则:
// prepare parameters
String name = "myTimerName";
String description = "this is a demo timer description";
String mqttEndpoint = "mymqttendpoint"; // 物接入实例名
String destTopic = "timer_send_msg_to_this_topic";
String msg = "{\"info\": \"this message is sent by timer myTimerName, every 30 seconds\"}";
long totalExecuteTimes = 100;
long period = 30; // send message every 30 seconds
// start first time execute period seconds later
long beginAt = System.currentTimeMillis() / 1000 + period;
// construct the CreateIotTimerRequest
CreateIotTimerRequest req = new CreateIotTimerRequest();
req.setName(name);
req.setDescription(description);
req.setEndpointName(mqttEndpoint);
req.setTopic(destTopic);
req.setMsg(msg);
req.setTimes(totalExecuteTimes);
req.setPeriod(period);
req.setBeginAt(beginAt);
// invoke the creation
String uuid = client.create(req).getUuid();
// now, uuid the unique id of the timer
删除定时器
请参考以下代码删除定时器:
// uuid为创建定时器返回的唯一id,请参考创建定时器代码
client.delete(uuid);
修改定时器
修改定时器信息
请参考以下代码修改定时器:
String name = "myTimerName_new";
String description = "this is a demo timer description_new";
String mqttEndpoint = "mymqttendpoint_new"; // 物接入实例名
String destTopic = "timer_send_msg_to_this_topic_new";
String msg = "{\"info\": \"this message is sent by timer myTimerName, every 30 seconds_new\"}";
long totalExecuteTimes = 100 + 200;
long period = 30 + 30; // send message every 60 seconds
UpdateIotTimerRequest req = new UpdateIotTimerRequest();
req.setName(name);
req.setDescription(description);
req.setEndpointName(mqttEndpoint);
req.setTopic(destTopic);
req.setMsg(msg);
req.setTimes(totalExecuteTimes);
req.setPeriod(period);
// uuid为创建定时器返回的唯一id,请参考创建定时器代码
client.update(req, uuid);