A sensor reading is a measurement record produced by an IoT sensor, such as a temperature or proximity observation. Sensor readings flow to Kafka topics, where Kafka Streams applications can monitor, enrich, and aggregate them. section 9.1 section 8.6.3
A reading can serve several processing roles:
- Feed a running aggregation that tracks count, sum, average, highest value, and threshold exceedances. section 9.1
- Start, continue, or close a data-driven aggregation when values cross a threshold; inactivity can trigger emission after ten seconds. section 10.3
- Supply sensor identity or measurement data for joining with metadata held in a GlobalKTable, even when the original record has no key. section 8.6.3
Manufacturing temperature monitoring
A production line publishes temperature readings continuously. The stream ignores values below a configured threshold, aggregates sustained high readings, and emits the result when the temperature falls, enough readings arrive, or ten seconds pass without another high reading. section 10.3
Listing 9.1 Creating an aggregation to track IoT temperature sensor readings
KStream<String,Double> iotHeatSensorStream =
builder.stream("heat-sensor-input",
Consumed.with(stringSerde, doubleSerde));
iotHeatSensorStream.groupByKey() #1
.aggregate(() -> new IotSensorAggregation(tempThreshold), #2
aggregator,
Materialized.with(stringSerde, aggregationSerde))
.toStream()
.to("sensor-agg-output", Produced.with(
stringSerde, aggregationSerde)); #3
Inspect the Kafka Streams topology that consumes heat-sensor readings, groups them by key, aggregates them, and writes sensor results to an output topic. section 9.1
