Streams application exits after a few seconds

I have this streams application. It starts fine and waits and listens for incoming messages (also printed using peek). I added a reduce operation on this stream (TimeWindowedKStream) and if I run it with this addition it prints the first message and then exits and is back to the command prompt. Any idea why this happens. There is not exception printed.

1 Like

When you call KafkaStreams#start() it will start background processing threads. If you don’t write specific code your main() method might exit and the JVM is terminates.

Cf kafka/ at 4a572d2beaa6c46fa95f2883149e055757c7fb4e · apache/kafka · GitHub that uses a “latch” to prevent main() from exiting until CTRL+C is hit (that will execute the registered shutdown hook).

I did implement this hook but still does not seem to work. The funny thing is , I have a version of this code that uses JSON and it works perfectly fine as expected.

This is the same version but using Avro, and I am experiencing very funny behavior. For example, I have implemented a transformer and when I run the code, I see that it executes init() and then close() first even before it reads from topic and prints the message (peek). Very strange. Maybe it is using some of the intermediate stream artifacts created by the JSON version?

My gut feeling is, that that there might be some deserialization issues. Did you check the logs for errors?

If you start the program, init() would be called and KafkaStreams tried to deserialize the first record. If deserialization fails, it would cleanup and close() the transformer again before it shuts down.