Need help w init kafka consumer (have an error w listenner)

Consumer: https://github.com/iamrutra/microservice-social-media/tree/main/notification-service/src/main/java/com/iamrutra/notification_service Producer: https://github.com/iamrutra/microservice-social-media/tree/main/post-service/src/main/java/com/iamrutra/post_service/kafka Hey, guys! I'm doing a project for myself and the project clearly needs a kafka. I can't connect kafka to the project because it shows these errors org.springframework.kafka.listener.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message Endpoint handler details: Method [public void com.iamrutra.notificationservice.events.EventHandler.NewCommentHandler(com.iamrutra.notificationservice.events.CommentEvent)] Bean [com.iamrutra.notification_service.events.EventHandler@1e2077fc] Caused by: org.springframework.messaging.converter.MessageConversionException: Cannot handle message Caused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [java.lang.String] to [com.iamrutra.notification_service.events. CommentEvent] for GenericMessage [payload={“senderName”: “si9gma”, “authorEmail”: “john.sigma@example.com”, “authorId”:103, “postId”:152, “time”:[2024,9,20,15,8,54,933204300]}, headers={kafka_offset=30, kafka_consumer=org. springframework.kafka.core.DefaultKafkaConsumerFactory$ExtendedKafkaConsumer@6146cb7b, kafka_timestampType=CREATE_TIME, kafka_receivedPartitionId=0, kafka_receivedTopic=comment-topic, kafka_receivedTimestamp=1726837735006, __TypeId=[B@2fbe9274, kafka_groupId=notification-service}]] As I make a request to create a comment, everything is created and sent to kafka, but the recipient does not want to work with it as an error of conversion from string to CommentEvent, although it stands in the configs everything is correct. Any help would be appreciated, thanks!
GitHub
microservice-social-media/notification-service/src/main/java/com/ia...
microservice-social-media. Contribute to iamrutra/microservice-social-media development by creating an account on GitHub.
GitHub
microservice-social-media/post-service/src/main/java/com/iamrutra/p...
microservice-social-media. Contribute to iamrutra/microservice-social-media development by creating an account on GitHub.
3 Replies
JavaBot
JavaBotthis hour
This post has been reserved for your question.
Hey @iamrutra (Artur)! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Toerktumlare
Toerktumlare20h ago
why have you defined Object in the KafkaTemplate KafkaTemplate<String, Object> Kafka per default sends Strings, it cant handle anything else. So if you say you are sending an Object, it will per default send a string. If you on the other hand define KafkaTemplate<String, CommentEvent> kafka will still send it as a string but also include type information in one of its headers so the consumers know what to deserialize the string into. Also if you define the correct type, the consumer will prolly still not work as you have to define in the consumer JsonDeserializer.TRUSTED_PACKAGES in the consumer configuration options. Which is a security feature. That is there to prevent an unknown producer to produce a malicious string, and then provide malicious type information to tell the consumer to consume the string and deserialize it into some class that will perform code execution on this random malicious string. If you know that you will not have any unknown producers, then you can disable this security feature by setting props.put(JsonDeserializer.TRUSTED_PACKAGES, "*"); in your consumer config. This says that we trust ever event that comes. In an enterprise environment, you have a shared library that contains the Event class that both the producer and consumer includes so they have the exact same object on both sides and then you define its package as trusted. I hope thats enough for you to get it working
JavaBot
JavaBot15h ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server