问题
I need a stream to group values from topic A, send the grouped values to topic B, and send the sum of those grouped values over a tumbling time window to topic C. Is it possible to do that in Kafka? Or can a stream both read and write from one topic only?
回答1:
Yes. For example you can split a input stream and write to different topics:
KStream stream = ...
KStream[] splitStream = stream.branch(...);
splitStream[0].to("topic-1");
splitStream[1].to("topic-2");
You can also use a more dynamic approach via to(TopicNameExtractor)
.
You can also "broadcast" a stream to apply different logic. Reusing the same KStream
variable ensures that each record is logically duplicated and processed through multiple parallel downstream operations:
KStream stream = ...
KStream filterdStream = stream.filter();
KTable count = stream.groupBy().count();
来源:https://stackoverflow.com/questions/51745967/is-it-possible-for-a-kafka-stream-to-write-output-to-two-different-topics