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.

OpenSearch consumer implementation: Part 6 replaying data

OpenSearch consumer implementation: Part 6 replaying data - Kafka Tutorial

From the course: Complete Guide to Apache Kafka for Beginners

OpenSearch consumer implementation: Part 6 replaying data

So, let's go ahead and just add the necessary code to gracefully shut down this piece of consumer. So if we go back into our Kafka basics and then we go to consumer demo we've shut down, we can copy the part around the shutdown. So we have the thread right here that I'm going to go back and copy right underneath my consumer. So we have a reference to the main thread. Then we have a try already. So we have the try around the while. So this is perfect. So what we need just is the part around the catch. So let's catch some exceptions. So back into my open source consumer at the very bottom of my try, which is right here, I'm going to paste things. So in case of a wake up exception, the consumer is starting to shut down and another exception then we'll print it to the log. And here we finally closed the consumer and we may as well close the OpenSearch client. So let's do this dot close to close both my clients. And now this should be enough to have the closing logic and have a graceful…

Contents