KStreams -> like logs, which is insert only and it is infinitybash
KTablesapp
Introduce KTable:less
Stateless means that the result of a transformation only depends on the data-point you processui
example (y = 2x): 1 -> 2 , 300 -> 600. In this case you only focus on the current state of data/operation.this
Stateful means that the result of a transformation also depends on external information - the state3d
example: hello -> , hello -> 2. the second hello is 2, because the calculation based on the first one.code
Example for Brach:orm
Read and write from / to Topic:blog
kafka-topics --zookeeper localhost:2181 --create --topics test --partitions 1 --replication-factor 3 \kafka
--config clean.policy=compact \
--config min.cleanable.dirty.ratio=0.5 \
--config segment.ms=10000
Example below shows
1. create a topic with log-compaction
2. produce (background) and consume data
3. consume data again after log-compaction happened.
Sometimes it is helpful to transform a KTable to a KStream in order to keep a changelog of all the changes to the KTable!
This can be easily achieved in one line of code:
KTable<byte[], String> table = ... ; // also a variant of 'toStream' exists that allows you to select a new key for the resulting stream KStream<byte[], String> stream = table.toStream();
There are two way:
KTable<String, Long> table = stream.groupByKey().count();
// write to Kafka stream.to("my-topic"); // read from Kafka as a table KTable<String, String> table = builder.table("my-topic");
With this operation you will have all of advatages of KTable, which means it will receive all of update state and delete ( if value is null ) information of a Stream.