Spring Boot + Apache Kafka Tutorial - #12 - Create REST API to Send JSON Object
Вставка
- Опубліковано 11 тра 2022
- Welcome to Spring Boot + Apache Kafka Tutorial series.
In this lecture, we will create a REST API to send a JSON message in request. The REST API intern converts JSON into a User object and sends it to Kafka Producer. Kafka Producer intern sends that user object to Kafka topic.
#springboot #kafka #javaguides
Complete playlist at • Spring Boot + Apache K...
GitHub link: github.com/RameshMF/springboo...
Спасибо огромное!!!! Ты очень хорошо все объясняешь.👍👍👍👍
many thanks about your tutorial, cuz your video i very help for learning about kafka
great explanation
Those who are getting the error trying to cast your User object to a String may need to update your producer properties to have a key serializer and value serializer instead of "deserializer".
I have added this but still got same error
Greate lessons
Nice presentation and explanation.
Glad you liked it!
Please explain how to consume old data from Kafka after the old data get updated. Is it a possible scenario atleast from interview point of view ?
How to consume data by using browser or postman?
Some of the windows commands are not working for me giving "The syntax for the command is incorrect" specially when using --from-beginning
At 2:07, you have added PostMapping("/publish") and in the previous video in MessageController class you have added GetMapping("/publish"). Can you please explain the reason behind it? Please clarify this.
As per my understanding at both the places it should be GetMapping annotation only.
Hi, I am getting 405 request method not supported, but I can’t understand why, anyone can help me?
hello sir,
I am getting null pointer exception related to kafka template while using rest api to send json object on console.
And in postman it is showing internal server error.
please help.
I am getting the same error too did u get solution?
@@JustFootBallThings623 my code is correct...so i guess its due to some of the libraries or dependencies missing on our IDE unlike used in lecture. In better way i skipped it and and continued with lecture.
in next lecture he made real time project. Thats important.
add
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.kafka.support.serializer.JsonSerializer;
to every java class work for me
recheck the previous learning vedio u must have missed creating constructor for kafka template,so u r getting null pointer exception
hai sir. i tried to send Json Message to kafka topic but am getting internal server error in postman . As well as in intellij, ERROR [dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.kafka.common.errors.SerializationException: Can't convert value of class in.inspired.services.model.User to class org.apache.kafka.common.serialization.StringSerializer specified in value.serializer] with root cause java.lang.ClassCastException: class in.inspired.services.model.User cannot be cast to class java.lang.String (in.inspired.services.model.User is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')...how to overcome this error. kindly help in this
did you resolve it?
@@newtanagmukhopadhyay4716 yes sir. i resolved it. however thank you for your presence to help me.
@@elakkiyap5509 ah dont call me sir pls its embrassing for me. im just 22
@@newtanagmukhopadhyay4716oh. Am sorry.
Even I am getting this error, can u please help me to resolve this
Anyone please help me to resolve this error org.apache.kafka.common.errors.SerializationException: Can't convert value of class com.vinay.kafka.payload.User to class org.apache.kafka.common.serialization.StringSerializer
i also get this error
@@shanmugamsekar2070 Have u got a solution?
@@vinay2841
To ensure that the User class is properly serialized and deserialized as JSON, you need to add the necessary Jackson annotations.e.g. @JsonProperty annotation. Add this dependency in your pom.xml if using a spring boot project.
com.fasterxml.jackson.core
jackson-databind
Replace your KafkaConsumer class code with the below code if you are getting :- org.apache.kafka.common.errors.SerializationException: Can't convert value of class com.vinay.kafka.payload.User to class org.apache.kafka.common.serialization.StringSerializer
public class KafkaConsumer {
@KafkaListener(topics = "nepdroid", groupId = "myGroup")
public void consume(User user) {
log.info(String.format("Message received -> %s", user.toString()));
}
}