apache-kafka - Kafka:序列化时的消息大于您使用 max.request.size 配置配置的最大请求大小
问题描述
收到以下错误(Kafka 2.1.0):
2018-12-03 21:22:37.873 错误 37645 --- [nio-8080-exec-1] osksupport.LoggingProducerListener:发送带有 key='null' 和 payload='{82, 73, 70 的消息时抛出异常, 70, 36, 96, 19, 0, 87, 65, 86, 69, 102, 109, 116, 32, 16, 0, 0, 0, 1, 0, 1, 0, 68, -84,.. .' to topic recieved_sound: org.apache.kafka.common.errors.RecordTooLargeException: 序列化时消息为 1269892 字节,大于您使用 max.request.size 配置配置的最大请求大小。
我尝试了各种 SO 帖子中的所有建议。
我的 Producer.properties:
max.request.size=41943040
message.max.bytes=41943040
replica.fetch.max.bytes=41943040
fetch.message.max.bytes=41943040
服务器属性:
socket.request.max.bytes=104857600
message.max.bytes=41943040
max.request.size=41943040
replica.fetch.max.bytes=41943040
fetch.message.max.bytes=41943040
生产者配置(Spring Boot):
configProps.put("message.max.bytes", "41943040");
configProps.put("max.request.size", "41943040");
configProps.put("replica.fetch.max.bytes", "41943040");
configProps.put("fetch.message.max.bytes", "41943040");
消费者配置(SpringBoot):
props.put("fetch.message.max.bytes", "41943040");
props.put("message.max.bytes", "41943040");
props.put("max.request.size", "41943040");
props.put("replica.fetch.max.bytes", "41943040");
props.put("fetch.message.max.bytes", "41943040");
我还在最后 2 个文件中将字符串更改为数字。多次启动代理,并创建新主题。最初我遇到了org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept
错误,这些更改已解决,但这个新错误仍然没有运气。
解决方案
设置断点KafkaProducer.ensureValidRecordSize()
以查看发生了什么。
有了这个应用程序
@SpringBootApplication
public class So53605262Application {
public static void main(String[] args) {
SpringApplication.run(So53605262Application.class, args);
}
@Bean
public NewTopic topic() {
return new NewTopic("so53605262", 1, (short) 1);
}
@Bean
public ApplicationRunner runner(KafkaTemplate<String, String> template) {
return args -> template.send("so53605262", new String(new byte[1024 * 1024 * 2]));
}
}
我明白了
序列化时消息为 2097240 字节,大于您使用 max.request.size 配置配置的最大请求大小。
正如预期的那样;当我添加
spring.kafka.producer.properties.max.request.size=3000000
(这相当于您的配置,但使用 Spring Boot 属性),我得到
请求包含的消息大于服务器将接受的最大消息大小。
如果调试没有帮助,也许您可以发布一个完整的小应用程序来展示您所看到的行为。
推荐阅读
- python - 无法将关键字“id”解析为字段。选项有:完成、task_priority、text、user、user_id
- python-3.x - 从给定列表中,删除所有偶数(包括 0)并打印出结果列表
- jakarta-ee - 如何修复 DeploymentException:处理归档中的 glassfish-resources.xml(s) 时失败
- python - 更改导入包后修复导入的更好方法
- excel - 隐藏行的动态范围
- react-native - 如何在具有固定高度的水平 FlatList 上处理 Drag'n Drop 手势
- scala - 将数据帧写入 CSV 时出现 IndexOutOfBoundsException
- redis - 过期前删除的 Redis 键
- python - 为什么我的登录身份验证不起作用?此代码既不会将我重定向到任何地方,也不会向我显示任何错误
- tcl - 在 Tcl 脚本中查找 python 版本