Raman
Raman

Reputation: 717

Kafka Stream: Graceful shutdown

If we start the KafkaStream app in the background (say Linux), is there a way to signal from external, to the app, that can initiate the graceful shutdown?

Upvotes: 3

Views: 9607

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62310

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);

Upvotes: 7

Related Questions