报错信息如下所示:
Caused by: org.apache.kafka.common.errors.RecordTooLargeException: The message is 1527150 bytes when serialized which is larger than 1048576, which is the value of the max.request.size configuration.
从日志可以看出,kafka默认一次接收请求消息的最大量为1M,即1048576字节,从这我们可以想到解决方案将max.request.size调大。接下来就会配置属性spring.kafka.producer.max.request.size,然而这样并不能解决问题。原因在于org.springframework.boot.autoconfigure.kafka.KafkaProperties类中并没有提供max.request.size属性。KafkaProperties类中提供的一些kafka的核心属性,比如clientId,bootstrapServers,key-serializer,value-serializer等,将一些非核心的属性放置在org.apache.kafka.clients.producer.ProducerConfig类中,然后在KafkaProperties类中以属性properties的方式进行提供。properties是一个Map。配置的全写为:

spring.kafka.producer.properties.max.request.size=10485760

但是需要注意的是,在这里配置的值应该小于服务端配置的最大值,否则报如下错误:
org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.
如果要修改服务端配置,则需要修改两个地方,首先是server.properties,加入

message.max.bytes=12695150
然后是producer.properties,加入

max.request.size=12695150
注:
SpringBoot版本为2.3.3,kafka的版本为2.12-2.80。

下面是debug的过程;
太难调试了,暂时放弃了。。。查到了默认为1M大小,但什么时候开始解析spring.kafka.producer.properties.max.request.size这个属性的,并未调试到。

参考链接:
https://my.oschina.net/shyloveliyi/blog/1620012

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐