vendredi 6 mars 2020

In Kafka Streaming, is`StreamsBuilder` a builder class?

In general, a builder instance is used in the following way:

  builder.buildPartA();
  builder.buildPartB();
  co = builder.getResult();

In Kafka Streaming, isStreamsBuilder a builder class? For example, in https://kafka.apache.org/24/documentation/streams/ (also see below),

  • is builder.stream() an equivalence to builder.buildPartA()?
  • Is there no equivalence to builder.buildPartB()?
  • What do textLines.flatMapValues(), wordCounts.toStream() correspond to in a builder pattern?

Thanks.

StreamsBuilder builder = new StreamsBuilder();
KStream<String, String> textLines = builder.stream("TextLinesTopic");
KTable<String, Long> wordCounts = textLines
    .flatMapValues(textLine -> Arrays.asList(textLine.toLowerCase().split("\\W+")))
    .groupBy((key, word) -> word)
    .count(Materialized.<String, Long, KeyValueStore<Bytes, byte[]>>as("counts-store"));
wordCounts.toStream().to("WordsWithCountsTopic", Produced.with(Serdes.String(), Serdes.Long()));

KafkaStreams streams = new KafkaStreams(builder.build(), props);

Aucun commentaire:

Enregistrer un commentaire