kafka发送消息报错Exception thrown when sending a message with key='null'

图片说明

使用jps 命令
[1] 9795
[root@localhost kafka]# jps
10099 Jps
8294 Kafka
9574 NamesrvStartup
[1]+ Done bin/kafka-server-start.sh -daemon config/server.properties

发送接收消息的配置如下
1.appacliation.properties

spring.kafka.bootstrap-servers=192.168.209.128:9092
spring.kafka.consumer.group-id=0
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.batch-size=65536
spring.kafka.producer.buffer-memory=524288

2.java 发送接收消息
@GetMapping("/sendOrder")
public String sendOrder(@RequestParam("orderId")String orderId) {
kafkaTemplate.send("order",new Order(orderId));
return "success";
}

@KafkaListener(topics = {"order"})
public void receiveOrder(ConsumerRecord<?,?>consumer) {
    logger.info("{}-{}:{}",consumer.topic(),consumer.key(),consumer.value());
}

刚开始我执行了一个发送string 消息的,结果就是死循环一样不停的打印Exception 之前的消息,
哪位大佬给解决下,多谢。

https://www.cnblogs.com/yxlblogs/p/10115672.html 这个重新安装kafka 后问题解决,原来的使用String Serializable 也不行

https://blog.csdn.net/lzj3462144/article/details/78824138
https://blog.csdn.net/longxing_123/article/details/78533241

你kafka 默认的格式是自定义的string类型 你传的是对象 kafkaTemplate.send("order",new Order(orderId)); 这个地方不能传对象 ,如果要
传对象 请先实现kafka提供的自定义对象 在传对象

spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
这一坨是默认的string
这一坨可以自定义