在配置中添加json序列化器
java
spring:
application:
name: spring-boot-kafka-base
kafka:
bootstrap-servers: 192.168.225.128:9092
# 配置生产者序列化
producer:
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
# 配置默认的topic
template:
default-topic: test
发送对象消息
java
public void sendEvent5(){
kafkaTemplate.sendDefault(null,System.currentTimeMillis(),"k3",User.builder()
.age(10)
.name("小王")
.build());
}