Thursday, June 1, 2023

Kafka Streams KTable Arayüzü - Materialized View - Bir Key'in En Son Değerini Verir

Giriş
Şu satırı dahil ederiz
import org.apache.kafka.streams.kstream.KTable;
Açıklaması şöyle. Yani bir key'in en son değerini verir
Tables are bounded and mutable collections of data records that represent the latest state of entities or aggregates. 
Açıklaması şöyle
Kafka Streams supports the creation of materialized views through the KTable abstraction. You can perform aggregations, filtering, and transformations on the stream data and create materialized views that can be queried efficiently.
Açıklaması şöyle. Aynı KStream gibi stateful işlemleri destekler
Kafka Streams provides two main abstractions for processing data: KStream and KTable. 
- A KStream represents an unbounded stream of records that can be transformed with stateless operations such as mapping, filtering, joining, and aggregating. 
- A KTable represents a changelog stream of records that can be queried by key and updated with stateful operations such as counting, grouping, windowing, and joining.
Bir soru şöyle
Q: How can we retain the current state of the KTable while still preserving the history of events using log compaction?
A : To retain the current state of a KTable while preserving the history of events using log compaction, you can leverage the concept of changelog topics in Kafka Streams. The changelog topic serves as a durable, compacted log that maintains the complete history of all updates to the KTable. Here’s how you can achieve this:

1. Enable Log Compaction: Configure the changelog topic associated with the KTable to use log compaction by setting the cleanup.policy configuration of the topic to compact.

2. Configure the KTable: When defining the KTable in your Kafka Streams application, specify a materialized state store for the KTable using the Materialized API. This materialized state store is associated with the changelog topic and allows the application to store and retrieve the current state of the KTable.


No comments:

Post a Comment

kafka-consumer-groups.sh komutu

Giriş Bir topic'i dinleyen consumer'ları gösterir. Aynı topic'i dinleyen consumer group'ları olabilir. Her topic farklı part...