October 21, 2024
Chicago 12, Melborne City, USA
java

Kafka Streams and CompletableFuture (or asynch java api)


I am studing Apache Kafka Stream SPI. I am wondering is there are a way to execute asynch code inside of mapValues method. For example to retrieve data from external store. Is there is a way to interract with Kaska Streams in event-loop reactive style?

    StreamsBuilder streamsBuilder = new StreamsBuilder();
    streamsBuilder
            .stream("SOURCE_TOPIC", Consumed.with(Serdes.String(), Serdes.String()))
            .mapValues((readOnlyKey, value) -> value.toUpperCase()) 
            .to("DESTINATION_TOPIC", Produced.with(Serdes.String(), Serdes.String()));
    var topology = streamsBuilder.build()

    var kafkaStreams = new KafkaStreams(topology, properties);

how to replace this mapValues code

value.toUpperCase()

with:

CompletableFuture.completedFuture(value.toUpperCase())



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video