Has anyone managed to debug kafkastreams code written in Java 8 using IntelliJ IDEA?. I am running a simple linesplit.java code where it takes stream from one topic and splits it and sends it to another topic, but I have no idea where to keep the debug pointer to debug every message as it flows through linesplit.java.
Linesplit.java
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-linesplit");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
final StreamsBuilder builder = new StreamsBuilder();
// ------- use the code below for Java 8 and uncomment the above ---
builder.stream("streams-input")
.flatMapValues(value -> Arrays.asList(value.toString().split("\\W+")))
.to("streams-output");
// -----------------------------------------------------------------
final Topology topology = builder.build();
final KafkaStreams streams = new KafkaStreams(topology, props);
final CountDownLatch latch = new CountDownLatch(1);
// attach shutdown handler to catch control-c
Runtime.getRuntime().addShutdownHook(new Thread("streams-shutdown-hook") {
@Override
public void run() {
streams.close();
latch.countDown();
}
});
try {
streams.start();
latch.await();
} catch (Throwable e) {
System.exit(1);
}
System.exit(0);
}
Did you try peek?
Your example can be as follows (using peek function):
builder
.stream("streams-input")
.peek((k, v) -> log.info("Observed event: {}", v))
.flatMapValues(value -> Arrays.asList(value.toString().split("\\W+"))).
.peek((k, v) -> log.info("Transformed event: {}", v))
.to("streams-output");
I didn't run the code but this is how I do it normally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With