How to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object

How to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object

In the previous post, we had setup a Spring Kafka Application succesfully by explicitly configuration Kafka Factories with SpringBoot. But the messages had been used have String type. While in the development, POJO (Plain Old Java Object) are often used to construct messages. So with the tutorial, JavaSampleApproach will show how to use Spring Kafka … Continue reading "How to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object messages"

https://grokonez.com/spring-framework/spring-kafka/how-to-use-spring-kafka-jsonserializer-jsondeserializer-to-produceconsume-java-objects

How to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object messages

In the previous post, we had setup a Spring Kafka Application succesfully by explicitly configuration Kafka Factories with SpringBoot. But the messages had been used have String type. While in the development, POJO (Plain Old Java Object) are often used to construct messages. So with the tutorial, JavaSampleApproach will show how to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object messages.

Related Articles:

I. Technologies

– Java 8 – Maven build – Spring Boot – Apache Kafka – Spring Tool Suite editor

II. Overview

Spring Kafka Application - architecture

In the tutorial, we send and receive Java object messages to/from Apache Kafka, so ProducerFactory uses JsonSerializer.class and ConsumerFactory uses JsonDeserializer.class to serialize/deserialize Java objects to Json bytes.

  • KafkaProducerConfig:

@Bean
public ProducerFactory producerFactory() {
    ...
    configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
    return new DefaultKafkaProducerFactory<>(configProps);
}

@Bean
public KafkaTemplate kafkaTemplate() {
    return new KafkaTemplate<>(producerFactory());
}
  • KafkaConsumerConfig:

More at:

https://grokonez.com/spring-framework/spring-kafka/how-to-use-spring-kafka-jsonserializer-jsondeserializer-to-produceconsume-java-objects

How to use Spring Kafka JsonSerializer (JsonDeserializer) to produce/consume Java Object messages

spring kafka jsonserializer jsondeserializer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to start Spring Kafka Application with Spring Boot » grokonez

The Spring Apache Kafka (spring-kafka) provides a high-level abstraction for Kafka-based messaging solutions. And in the previous post, We had developed a Spring Kafka Application with the auto-configuration supported by SpringBoot (from version 1.5). But when we need explicitly configure Kafka factories (Kafka Producer and Kafka Consumer) for development, how to do it? So in … Continue reading "How to start Spring Kafka Application with Spring Boot"

Spring Boot with Apache Kafka Producer and Consumer example in 5 mins

You will learn how to create Kafka Producer and Consumer with Spring Boot in Java. GitHub Link: https://github.com/shameed1910/springboot-kafka.git You can s...

Spring Boot with Apache Kafka Producer and Consumer example in 5 mins

In this video, You will learn how to create Kafka Producer and Consumer with Spring Boot in Java.

Kafka Spark Streaming | Kafka Tutorial

🔥Intellipaat Kafka training: https://intellipaat.com/kafka-training-online/ 👉In this kafka spark streaming tutorial you will learn what is apache kafka, arch...

Spring Full Course - Learn Spring Framework in 4 Hours | Spring Framework Tutorial

This Edureka Spring Full Course video will help you learn Spring Framework from scratch with examples. This Spring Tutorial is ideal for both beginners as well as professionals who want to master the Spring Framework.