🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Welcome to Spring Boot + Apache Kafka Tutorial series. In this lecture, we will configure Kafka Producer and Consumer for JSON messages. Also, we will create a User class for serializing and deserializing.
Lecture - #10 - Configure Kafka Producer and Consumer for JSON Message
Transcript:
In this lecture, we will configure Kafka Producer and Consumer for JSON Serializer and Deserializer. Well, in the next upcoming lectures, we will see how to send and receive JSON object as a JSON byte array to and from Apache Kafka. Let's head over to the IntelliJ idea and let's change the application.properties file to configure JSON Serializer and Deserializer for Kafka Producer and Consumer. Well, let me head over to the IntelliJ IDEA, let's go to application.properties file over here. So here you can see we have used StringDeserializer and StringSerializer classes to serialize and deserialize message key right so we're going to keep StringDeserializer and StringSerializer classes from Kafka library for this message key we're not going to change the StringDeserializer and StringSerializer classes for this key, we're going to only change the message value. Okay, so here you can see right now we have StringDeserializer class from Kafka Library to deserializer the value for this Consumer. So let's go ahead and let's change it. So let's use JsonDeserializer from Spring Kafka Library. So let me comment on this and here I want to type the property spring.kafka.consumer.value- deserializer and then the value is org.springframework.kafka.support.serializer.JsonDeserializer Okay. Now we are using JsonDeserializer class from spring provided library, not from the Kafka library. Okay. So this JsonDeserializer is basically created by Spring Kafka library, not from Kafka library. Okay. Now we have configured JsonDeserializer for this Kafka Consumer. So a Consumer will basically, you know, convert JSON byte into the Java object by using this JsonDeserializer Now let's go ahead and let's see how to configure JsonSerializer class for this Kafka Producer. So right now we are using StringSerializer class to serialize the value from the Kafka Library right. So let me simply comment it out this and let me write the property. spring.kafka.producer.value-serializer: then type the value org.springframework .kafka.supoort.serializer.JsonSerializer Okay. It means that this Kafka Producer will basically convert Java object into JSON and then it will write to the Kafka topic. All right. Now we have configured Kafka Consumer and Kafka Producer for JsonDeserializer and JsonSerializer All right, great. Well, in a Kafka Consumer, we can also configure one more property that is spring.kafka .consumer.properties .spring.json.trusted.packages=* It means that Kafka Consumer can JsonDeserializer all the classes from this package. Okay, here star (*) meaning all the classes from this package. All right, perfect. Now we have configured Kafka Consumer and Producer for JsonDeserializer and JsonSerializer. All right, in the next lecture, we'll create a simple POJO class that we can write to the Kafka topic. All right, I will see you in the next lecture.
❮ Previous Lecture
Next Lecture ❯My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
🆕 High-Demand
80–90% OFF
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
🆕 High-Demand
80–90% OFF
ChatGPT + Generative AI + Prompt Engineering for Beginners
🚀 Trending Now
80–90% OFF
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
🌟 Top Rated
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
🌟 Top Rated
80–90% OFF
Testing Spring Boot Application with JUnit and Mockito
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Master Spring Data JPA with Hibernate
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
🎓 Student Favorite
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Comments
Post a Comment
Leave Comment