Class KafkaStreamBrancher<K,​V>

  • Type Parameters:
    K - Type of keys
    V - Type of values

    public final class KafkaStreamBrancher<K,​V>
    extends java.lang.Object
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      KafkaStreamBrancher<K,​V> branch​(org.apache.kafka.streams.kstream.Predicate<? super K,​? super V> predicate, java.util.function.Consumer<? super org.apache.kafka.streams.kstream.KStream<K,​V>> consumer)
      Defines a new branch.
      KafkaStreamBrancher<K,​V> defaultBranch​(java.util.function.Consumer<? super org.apache.kafka.streams.kstream.KStream<K,​V>> consumer)
      Defines a default branch.
      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 given KStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KafkaStreamBrancher

        public KafkaStreamBrancher()
    • Method Detail

      • branch

        public KafkaStreamBrancher<K,​V> branch​(org.apache.kafka.streams.kstream.Predicate<? super K,​? super V> predicate,
                                                     java.util.function.Consumer<? super org.apache.kafka.streams.kstream.KStream<K,​V>> consumer)
        Defines a new branch.
        Parameters:
        predicate - Predicate instance
        consumer - The consumer of this branch's KStream
        Returns:
        this
      • defaultBranch

        public KafkaStreamBrancher<K,​V> defaultBranch​(java.util.function.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's KStream
        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 given KStream.
        Parameters:
        stream - KStream to split
        Returns:
        the provided stream