kafka报org.apache.kafka.common.errors.RecordTooLargeException

    kakfa报错如下: 

java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.RecordTooLargeException: The message is 12792083 bytes when serialized which is larger than the maximum request size you have configured with the max.request.size configuration.

    原因是发送的消息过大,大于默认配置。其源码如下:

ProducerConfig.java

 .define(MAX_REQUEST_SIZE_CONFIG,
  Type.INT,
  1 * 1024 * 1024,
  atLeast(0),
  Importance.MEDIUM,
  MAX_REQUEST_SIZE_DOC)

可以看到默认是1M,只需要在配置kafka连接时,加入配置max.request.size即可,如下:

properties.put("bootstrap.servers", "172.16.40.4:9092");
properties.put("acks", "1");
properties.put("retries", 0);
properties.put("batch.size", 16384);
properties.put("linger.ms", 1);
properties.put("max.request.size", 12695150);
properties.put("buffer.memory", 33554432);
properties.put("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");

    但是需要注意的是,在这里配置的值应该小于服务端配置的最大值,否则报如下错误

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

   同时,消费端也要配置属性max.partition.fetch.bytes以接收大数据。

   

转载于:https://my.oschina.net/shyloveliyi/blog/1620012

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值