Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more

As describe in the docs ( https://kafka.apache.org/11/documentation/streams/tutorial ), it's recommended to register a shutdown hook that calls KafkaStreams#close() for a clean shutdown:

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);
                If the app is initiated as a background process, I assume control-c may not be applicable.  We can kill the stream app instance using the PID, however not sure if the above would enable a clean shutdown.  Please confirm
– Raman
                May 14 '18 at 4:58
                Ctrl-C sends a SIGINT signal, and a normal kill <pid> sends a SIGTERM. These signals are covered by a shutdown hook (see docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html and stackoverflow.com/a/2541618/1743580).  What is NOT covered is a SIGKILL from a kill -9 <pid>. I'd recommend to read the Java documentation -- this is not specific to Kafka's Streams API.
– Michael G. Noll
                May 14 '18 at 10:19
                Just one addition follow-up, we are on 0.10.1, so by adding a new thread only for the shutdown hook, is there a possibility of facing the same issue as listed in the following? stackoverflow.com/questions/42398294/…
– Raman
                May 16 '18 at 15:40
                This should not be an issue. The reported multi-threading issues affect the internal StreamThreads only.
– Matthias J. Sax
                May 16 '18 at 16:17
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.4.3.36511