我有 3 个流:
TStream<Double> tempReadings=topology.poll(tempSensor, 10, TimeUnit.SECONDS);
TStream<Double> co2Readings=topology.poll(co2Sensor, 10, TimeUnit.SECONDS);
TStream<Boolean> stationaryReadings=topology.poll(stationarySensor, 10, TimeUnit.SECONDS);
我目前从 3 个 JSON 对象创建 3 个独立的设备事件:
TStream<JsonObject> tempJson=tempReadings.map(tuple->{
JsonObject json=new JsonObject();
json.addProperty("Temperature", tuple);
return json;
});
TStream<JsonObject> co2Json=co2Readings.map(tuple->{
JsonObject json=new JsonObject();
json.addProperty("C02Level", tuple);
return json;
});
TStream<JsonObject> sensoryJson=stationaryReadings.map(tuple->{
JsonObject json=new JsonObject();
json.addProperty("isStationary", tuple);
return json;
});
我想通过将这些流连接在一起并创建 1 个具有三个属性(Temperature、C02Level 和 isStationary)的 JSON 对象来创建单个事件。
最佳答案
您可以union流,但这只会将一个元组放在另一个元组之后,并且您需要使用相同类型的流。
如果您想一次读取所有 3 个属性,您可以创建一个返回“读数”对象的传感器:
class Reading {
Double temperature;
Double c02Level;
Boolean isStationary;
}
关于java - 在 Apache Edgent 中加入不同类型的流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41280097/