Kafka:序列化时的消息大于您使用max.request.size配置配置的最大请求大小

问题描述 投票:2回答:3

得到以下错误(Kafka 2.1.0):

2018-12-03 21:22:37.873 ERROR 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

server.properties:

socket.request.max.bytes=104857600
message.max.bytes=41943040
max.request.size=41943040
replica.fetch.max.bytes=41943040
fetch.message.max.bytes=41943040

ProducerConfig(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");

ConsumerConfig(Spring Boot):

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");

我还将Strings更改为最后2个文件中的数字。多次启动经纪人,并创建新主题。我最初得到org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept错误,这已经通过这些更改得到修复,但仍然没有运气这个新错误。

apache-kafka kafka-consumer-api kafka-producer-api spring-kafka
3个回答
2
投票

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属性),我明白了

该请求包含的消息大于服务器将接受的最大消息大小。

如果调试没有帮助,也许你可以发布一个完整的小应用程序,展示你看到的行为。


0
投票

您应该以这种方式在生产者中设置配置

Props.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, "41943040");

0
投票

如果Kafka属性是服务器上的文件,则可以更改消息大小。

对于默认的sever.property文件

#/usr/local/kafka/config
#message.max.bytes=26214400

producer.properties->

# the maximum size of a request in bytes
# max.request.size=26214400

消费者也一样

© www.soinside.com 2019 - 2024. All rights reserved.