Spring Boot + Apache Kafka Tutorial - #20 - Kafka Consumer Implementation in Real World Project

Welcome to Spring Boot + Apache Kafka Tutorial series. In this lecture, we will implement Kafka consumer in our real-world project.

Lecture - #20 - Kafka Consumer Implementation in Real-World Project


Hey. Welcome back. In this lecture, we have configured copper consumer in our application. The properties found right in this lecture will implement a consumer to consume a data from the capture topic. Well, let's head over to the English idea and go to the main package. So make sure that you are in the right project. We are want to create the capture consumer capture consumer database project. So go to main package over here, right click on it new and then just Java class lets you closely capture capture data with the consumer something like this. Hit enter and let's annotate this class with add service annotation. So this will make this class as it's being built. And then let's go ahead and let's greater log instance, let's say private static, final logger from shell project and then variable name and then logger factory and then call log get logger API and then press class name that is Kafka database consumer but class perfect. Now we have created in does next create a method let's say public word and let's assume that the name is conjoint and let's annotate this method with hat capture. Listener Well, make sure that you chose capitalized navigation from Wajid or Spring Framework that captured or annotation package. Next, we need to pass topic and group idea to this annotation. So just call topics attribute and then pass the topic name. Well, we have a unit topic name as Wikimedia Wikimedia underscore recent change. Right? So this is a topic name. We have a given next. We need to also provide the group party. Well, the group party that we have joined is my group. Right so let's have a group idea was here so just call group. I do it and then pass group ideas. My group now get perfect. So if you can go to application group properties file, we have a given group idea in my group right next to go back to our consumer class. And here you can see for this consumer method we need to pass the perimeter type string. So let's say you went message public. Now let's log this message. In order to do that, let's use a logger instance and then using permitted and then use string provided for method to permit the string string dot format and then say let's say message received and then placeholder and then pass you int message. Well here is a typo. There should be event message, resource, something like this. Perfect. Now we have implemented copycat consumer to consume data from the this particular copycat dynamic. Okay, now let's run this by consumer and let's see how this works. So in order to run this, what we need to do is we need to just render Springwood this project. So go to manage to kill us. All right. And just run this project and let's see how this, you know, how this cupcake consumer will read the data from the part of individual again able to see in a control unit message issue. So this is a log statement that we have written in to capture consumer. Right? So let me go to a consumer and you can see the statement here and message received. Okay. And, you know, kind you can see you end message received. It means that the cupcake consumer that we have written to consume the data from the topic is working as expected. And you can see the event data. Now, let's go ahead and let's run. Capture producer and capture consumer together and let's see the result. So in order to run the capture, producers will go to publish their Wikimedia project and render project. So by using this meaning different class, you can render project now. Look up capability. Start reading the realtime stream data from the Wikimedia. Right now, finally, let's render capture consumer. Well, in order to run the capture consumer, go to capture consumer database project and go to meaning different class that is being put consumer application. And just to this project and you can see in a console there are two tabs first tab is being put. Put is in application, second harvest, Springwood consumer application and you can see the logs of Springwood consumer application event message received. Okay. So apparently you can see both capture producer and capture consumer result here where Link is a capture producer, we can able to see the log event data followed by the unit and in case up capture consumer, you can able to see the log event message issued followed by the event. Okay. It means that the capture producer and capture consumer both are working as expected. Okay, great. In next lecture, what you will do will configure my cycle database in our consumer project, and we will see how to seal these events in domestic database. All right, great. I will see you in the next lecture.