问题
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?
回答1:
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);
来源:https://stackoverflow.com/questions/50322086/kafka-stream-graceful-shutdown