规则引擎

创建规则

DeviceRuleRequest request = new DeviceRuleRequest();
request.setName("ruleTest");

List<DeviceRuleDestination> destinationList = new ArrayList<DeviceRuleDestination>(1);
DeviceRuleDestination destination = new DeviceRuleDestination();
destination.setKind(DeviceRuleDestination.KindType.TSDB);
destination.setValue("test222.tsdb-106tunjjq367.tsdb.iot.gz.baidubce.com");
destinationList.add(destination);
request.setDestinations(destinationList);

List<DeviceRuleSource> sourceList = new ArrayList<DeviceRuleSource>(1);
DeviceRuleSource source = new DeviceRuleSource();
source.setCondition(">=");
source.setType(SchemaProperty.PropertyType.STRING);
source.setName("temperature");
sourceList.add(source);
request.setSources(sourceList);

DeviceRuleResponse deviceRuleResponse = client.createDeviceRule("deviceName", request);
String id = deviceRuleResponse.getId(); // 规则对应的id
String deviceName = deviceRuleResponse.getDeviceName(); // 规则对应的设备名称
String name = deviceRuleResponse.getName(); // 规则名称
List<DeviceRuleSourceDetail> sources = deviceRuleResponse.getSources(); // 规则的具体约束条件
List<DeviceRuleDestinationDetail> destinations = deviceRuleResponse.getDestinations(); // 处理后的消息写往的目的的数组
boolean enable = deviceRuleResponse.getEnable(); // 条件是否开启
long createTime = deviceRuleResponse.getCreateTime(); // 创建时间
long updateTime = deviceRuleResponse.getUpdateTime(); // 更新时间

修改规则

String deviceName = "deviceTest";
DeviceRuleRequest request = new DeviceRuleRequest();
request.setName("ruleName");
List<DeviceRuleSource> sourceList = new ArrayList<DeviceRuleSource>();
DeviceRuleSource source = new DeviceRuleSource();
source.setCondition(">=");
source.setType(SchemaProperty.PropertyType.STRING);
source.setName("temperature");
sourceList.add(source);
request.setSources(sourceList);
List<DeviceRuleDestination> destinationList = new ArrayList<DeviceRuleDestination>();
DeviceRuleDestination destination = new DeviceRuleDestination();
destination.setKind(DeviceRuleDestination.KindType.TSDB);
destination.setValue("test222.tsdb-106tunjjq367.tsdb.iot.gz.baidubce.com");
destinationList.add(destination);
request.setDestinations(destinationList);
DeviceRuleResponse deviceRuleResponse = client.modifyDeviceRule(deviceName, request);
String id = deviceRuleResponse.getId(); // 规则对应的id
String deviceName2 = deviceRuleResponse.getDeviceName(); // 规则对应的设备名称
String name = deviceRuleResponse.getName(); // 规则名称
List<DeviceRuleSourceDetail> sources = deviceRuleResponse.getSources(); // 规则的具体约束条件
List<DeviceRuleDestinationDetail> destinations = deviceRuleResponse.getDestinations(); // 处理后的消息写往的目的的数组
boolean enable = deviceRuleResponse.getEnable(); // 条件是否开启
long createTime = deviceRuleResponse.getCreateTime(); // 创建时间
long updateTime = deviceRuleResponse.getUpdateTime(); // 更新时间

删除规则

String deviceName = "deviceTest";
client.removeDeviceRule(deviceName);

禁用规则

String deviceName = "deviceTest";
client.disableDeviceRule(deviceName);

启动规则

String deviceName = "deviceTest";
client.enableDeviceRule(deviceName);