PunctuationType.WALL_CLOCK_TIME schedules a Punctuator using the Kafka Streams environment’s system clock rather than timestamps extracted from records. It suits periodic work that should continue even when event flow is sporadic. section 10.2.1 section 10.2.2
Use wall-clock punctuation when:
- The application must perform activity regularly regardless of data flow. section 10.2.2
- A processor schedules its Punctuator through ProcessorContext.schedule(Duration, PunctuationType, Punctuator). section 10.2.1
- Timing can be approximate: wall-clock progress is observed during polling, and precision depends on polling-cycle duration. section 10.2.2
Stock-performance processor
A stock-performance processor can schedule its punctuator for a ten-second interval with WALL_CLOCK_TIME. The processor can then examine accumulated stock data approximately every ten seconds, even when trades arrive irregularly. By contrast, STREAM_TIME waits for extracted timestamps to advance. section 10.2.1 section 10.2.2
Listing 10.5 Stock-performance application with a custom processor
Topology topology = new Topology();
String stocksStateStore = "stock-performance-store";
double differentialThreshold = 0.02; #1
KeyValueBytesStoreSupplier storeSupplier =
Stores.inMemoryKeyValueStore(stocksStateStore); #2
StoreBuilder<KeyValueStore<String, StockPerformance>> storeBuilder
= Stores.keyValueStoreBuilder(
storeSupplier, Serdes.String(), stockPerformanceSerde); #3
topology.addSource("stocks-source",
stringDeserializer,
stockTransactionDeserializer,
"stock-transactions")
.addProcessor("stocks-processor", #4
new StockPerformanceProcessorSupplier(storeBuilder),
"stocks-source")
.addSink("stocks-sink",
"stock-performance",
stringSerializer,
stockPerformanceSerializer,
"stocks-processor"); #5
Inspect the custom stock processor topology to see the source, state store, processor, and sink that provide the surrounding implementation context for scheduling. section 10.2.1
