From the course: Complete Guide to Apache Kafka for Beginners

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Java consumer: Graceful shutdown

Java consumer: Graceful shutdown

Hi, this is Stephane from Conduktor and in this demo, we're going to add a shutdown hook to our consumer code. And this is going to allow us to just properly shut down the consumer just like we did previously, properly shut down the producer. Let's duplicate this consumer demo and I'll call this one consumer demo with shutdown. Okay. So we are done. We're going to keep the same Java application for now. We're going to keep the properties all the way. This is perfect and we're going to keep the consumer. But now we're going to actually, just before the subscribe creates what's called a shutdown hook. So the first thing we need to do is to get a reference to the main thread, the current thread. So what we do is that we do final thread main thread Equals thread.current thread. And this is a reference to the thread that is running my program. So this is the main thread because we are in the main method right now. So it's a reference because we'll be using it in a few seconds. and then we…

Contents