Reputation: 3490
In Kafka(0.11.0.1) Streams, A demo app Play with a Streams Application
// Serializers/deserializers (serde) for String and Long types
final Serde<String> stringSerde = Serdes.String();
final Serde<Long> longSerde = Serdes.Long();
// Construct a `KStream` from the input topic "streams-plaintext-input", where message values
// represent lines of text (for the sake of this example, we ignore whatever may be stored
// in the message keys).
KStream<String, String> textLines = builder.stream(stringSerde, stringSerde, "streams-plaintext-input");
KTable<String, Long> wordCounts = textLines
// Split each text line, by whitespace, into words.
.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
// Group the text words as message keys
.groupBy((key, value) -> value)
// Count the occurrences of each word (message key).
.count("Counts")
// Store the running counts as a changelog stream to the output topic.
wordCounts.to(stringSerde, longSerde, "streams-wordcount-output");
And step 5, after process some datas, we could see compacted KV pairs(e.g. streams 2) in sink topic streams-wordcount-output,
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092
--topic streams-wordcount-output \
--from-beginning \
--formatter kafka.tools.DefaultMessageFormatter \
--property print.key=true \
--property print.value=true \
--property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer \
--property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer
all 1
streams 1
lead 1
to 1
kafka 1
hello 1
kafka 2
streams 2
The question is how does KTable wordCounts in the above data write data to topic streams-wordcount-output in Key-Value style?
The option cleanup.policy of topic streams-wordcount-output seems to be the default value, delete
, not compact
(via bin/kafka-configs.sh)
Upvotes: 0
Views: 2593
Reputation: 62350
All input and output topics are "out of scope" of Kafka Streams. It's the users responsibility to create and configure those topics.
Thus, your topic "streams-wordcount-output"
will have the config you specified when creating the topic.
Upvotes: 3