Class KafkaStreamBrancher<K,V>
java.lang.Object
org.springframework.kafka.support.KafkaStreamBrancher<K,V>
- Type Parameters:
K
- Type of keysV
- Type of values
Provides a method-chaining way to build
branches
in
Kafka Streams processor topology.
Example of usage:
new KafkaStreamBrancher<String, String>()
.branch((key, value) -> value.contains("A"), ks->ks.to("A"))
.branch((key, value) -> value.contains("B"), ks->ks.to("B"))
//default branch should not necessarily be defined in the end
.defaultBranch(ks->ks.to("C"))
.onTopOf(builder.stream("source"))
- Since:
- 2.2.4
- Author:
- Ivan Ponomarev, Artem Bilan
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbranch
(org.apache.kafka.streams.kstream.Predicate<? super K, ? super V> predicate, Consumer<? super org.apache.kafka.streams.kstream.KStream<K, V>> consumer) Defines a new branch.defaultBranch
(Consumer<? super org.apache.kafka.streams.kstream.KStream<K, V>> consumer) Defines a default branch.Terminating method that builds branches on top of givenKStream
.
-
Constructor Details
-
KafkaStreamBrancher
public KafkaStreamBrancher()
-
-
Method Details
-
branch
public KafkaStreamBrancher<K,V> branch(org.apache.kafka.streams.kstream.Predicate<? super K, ? super V> predicate, Consumer<? super org.apache.kafka.streams.kstream.KStream<K, V>> consumer) Defines a new branch.- Parameters:
predicate
-Predicate
instanceconsumer
- The consumer of this branch'sKStream
- Returns:
this
-
defaultBranch
public KafkaStreamBrancher<K,V> defaultBranch(Consumer<? super org.apache.kafka.streams.kstream.KStream<K, V>> consumer) Defines a default branch. All the messages that were not dispatched to other branches will be directed to this stream. This method should not necessarily be called in the end of chain.- Parameters:
consumer
- The consumer of this branch'sKStream
- Returns:
this
-
onTopOf
public org.apache.kafka.streams.kstream.KStream<K,V> onTopOf(org.apache.kafka.streams.kstream.KStream<K, V> stream) Terminating method that builds branches on top of givenKStream
.- Parameters:
stream
-KStream
to split- Returns:
- the provided stream
-