generated from okp4/template-oss
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement minimal topology (for example)
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.okp4.processor.cosmos | ||
|
||
import org.apache.kafka.common.serialization.Serdes | ||
import org.apache.kafka.streams.KeyValue | ||
import org.apache.kafka.streams.StreamsBuilder | ||
import org.apache.kafka.streams.Topology | ||
import org.apache.kafka.streams.kstream.Consumed | ||
import org.apache.kafka.streams.kstream.Named | ||
import org.apache.kafka.streams.kstream.Produced | ||
import org.slf4j.LoggerFactory | ||
import java.util.* | ||
|
||
/** | ||
* Simple Kafka Stream Processor that consumes a message on a topic and returns a new message on another. | ||
*/ | ||
fun topology(props: Properties): Topology { | ||
val logger = LoggerFactory.getLogger("com.okp4.processor.cosmos.topology") | ||
val topicIn = requireNotNull(props.getProperty("topic.in")) { | ||
"Option 'topic.in' was not specified." | ||
} | ||
val topicOut = requireNotNull(props.getProperty("topic.out")) { | ||
"Option 'topic.out' was not specified." | ||
} | ||
|
||
val streamsBuilder = StreamsBuilder() | ||
|
||
streamsBuilder.stream(topicIn, Consumed.with(Serdes.String(), Serdes.String()).withName("input")) | ||
.peek({ _, _ -> logger.info("Received a message") }, Named.`as`("log")) | ||
.map({ k, v -> KeyValue(k, "Hello $v!") }, Named.`as`("map-value")) | ||
.to(topicOut, Produced.with(Serdes.String(), Serdes.String()).withName("output")) | ||
|
||
return streamsBuilder.build() | ||
} |