我有 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 对象来创建单个事件。