物接入IoT Hub

    物管理转储TSDB

    创建带TSDB格式的规则

    String deviceName = "deviceTest";
    DeviceFormatRuleRequest request = new DeviceFormatRuleRequest();
    request.setName("TsdbRule");
    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);
    DeviceRuleFormat deviceRuleFormat = new DeviceRuleFormat();
    deviceRuleFormat.setMetric("newMetricName");
    deviceRuleFormat.setMode(DeviceRuleFormat.ModeType.FIELD);
    request.setFormat(deviceRuleFormat);
    DeviceFormatRuleResponse response = client.createTsdbFormatRule(deviceName, request);
    String id = response.getId(); // 规则对应的id
    String deviceName2 = response.getDeviceName(); // 对应的设备名称
    String name = response.getName(); // 规则名称
    List<DeviceRuleSourceDetail> sources = response.getSources(); // 规则的具体约束条件
    List<DeviceRuleDestinationDetail> destinations = response.getDestinations(); // 处理后的消息写往的目的地数组
    DeviceRuleFormat format = response.getFormat(); // 转存TSDB数据的格式定义
    boolean enable = response.getEnable(); // 是否开启
    long createTime = response.getCreateTime(); // 创建时间
    long updateTime = response.getUpdateTime(); // 更新时间

    获取带TSDB格式的规则详情

    String deviceName = "deviceTest";
    DeviceFormatRuleResponse response = client.getTsdbFormatRule(deviceName);
    String id = response.getId(); // 规则对应的id
    String deviceName2 = response.getDeviceName(); // 对应的设备名称
    String name = response.getName(); // 规则名称
    List<DeviceRuleSourceDetail> sources = response.getSources(); // 规则的具体约束条件
    List<DeviceRuleDestinationDetail> destinations = response.getDestinations(); // 处理后的消息写往的目的地数组
    DeviceRuleFormat format = response.getFormat(); // 转存TSDB数据的格式定义
    boolean enable = response.getEnable(); // 是否开启
    long createTime = response.getCreateTime(); // 创建时间
    long updateTime = response.getUpdateTime(); // 更新时间

    修改带TSDB格式的规则

    String deviceName = "deviceTest";
    DeviceFormatRuleRequest request = new DeviceFormatRuleRequest();
    request.setName("TsdbRule");
    List<DeviceRuleSource> sourceList = new ArrayList<DeviceRuleSource>();
    DeviceRuleSource source = new DeviceRuleSource();
    source.setCondition(">=");
    source.setType(SchemaProperty.PropertyType.STRING);
    source.setName("temperature");
    sourceList.add(source);
    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.setSources(sourceList);
    request.setDestinations(destinationList);
    DeviceRuleFormat deviceRuleFormat = new DeviceRuleFormat();
    deviceRuleFormat.setMetric("newMetricName");
    deviceRuleFormat.setMode(DeviceRuleFormat.ModeType.FIELD);
    request.setFormat(deviceRuleFormat);
    client.modifyTsdbFormatRule(deviceName, request);
     
    DeviceFormatRuleResponse response = client.getTsdbFormatRule(deviceName);
    String id = response.getId(); // 规则对应的id
    String deviceName2 = response.getDeviceName(); // 对应的设备名称
    String name = response.getName(); // 规则名称
    List<DeviceRuleSourceDetail> sources = response.getSources(); // 规则的具体约束条件
    List<DeviceRuleDestinationDetail> destinations = response.getDestinations(); // 处理后的消息写往的目的地数组
    DeviceRuleFormat format = response.getFormat(); // 转存TSDB数据的格式定义
    boolean enable = response.getEnable(); // 是否开启
    long createTime = response.getCreateTime(); // 创建时间
    long updateTime = response.getUpdateTime(); // 更新时间
    上一篇
    规则引擎
    下一篇
    版本说明