kafka命令行消费kafka-console-consumer.sh 报错 whose size is larger than the fetch size 1048576

kafka命令行消费kafka-console-consumer.sh 报错 whose size is larger than the fetch size 1048576

问题

[appuser@node01 kafka-0.10.0]$ bin/kafka-console-consumer.sh --bootstrap-server node01:9092,node02:9092,node03:9092 --topic topic_test1 --new-consumer
[2020-04-02 14:17:30,184] ERROR Error processing message, terminating consumer process:  (kafka.tools.ConsoleConsumer$)
org.apache.kafka.common.errors.RecordTooLargeException: There are some messages at [Partition=Offset]: {topic_test1-0=74691861} whose size is larger than the fetch size 1048576 and hence cannot be ever returned. Increase the fetch size, or decrease the maximum message size the broker will allow.
Processed a total of 0 messages

分析

kafka 单条消息过大,消费者读取数据大小和消费端配置max.partition.fetch.bytes(一次fetch请求,从一个partition中取得的records最大大小,默认值1024=1M)比较,超过此配置值,就会抛出上面异常信息。

注:针对于单条数据过大这种情况,如果真是场景避免不了,在生产端、broker、消费端都需要进行配置,如果不进行配置,数据大小超过默认配置,数据会被丢失。

broker
message.max.bytes :10000000(10M),broker server能接受消息体的最大值
replica.fetch.max.bytes :10240000(10M),这是单个消息的最大值broker可复制的消息的最大字节数,比message.max.bytes大,否则broker会接收此消息,但无法将此消息复制出去,从而造成数据丢失,但是不能太大!!!不然复制的时候容易内存溢出
消费端consumer
fetch.message.max.bytes:10000000(10M)这是消费者能读取的最大消息,大于或等于message.max.bytes,如果message.max.bytes大于fetch.message.max.bytes,就会导致consumer分配的内存放不下一个message。

生产端producer
max.request.size:10000000(10M)这是生产者能请求的最大消息,大于或等于message.max.bytes
kafka jvm参数调整

堆内存:kafka-server-start.sh文件的 export KAFKA_HEAP_OPTS="-Xmx4G -Xms4G"

真实案例:生产中遇到过kafka数据丢数情况,发现单条数据大小过大,导致数据丢失,进行生产端、broker、消费端配置解决。

本次只针对kafka-console-consumer.sh 命令行消费单条数据过大,进行调整,正常消费数据。

解决

[appuser@node01 kafka-0.10.0]$bin/kafka-console-consumer.sh --bootstrap-server node01:9092,node02:9092,node03:9092 --topic topic_test1  --consumer.config config/consumer_jaas.properties --new-consumer

vim consumer_jaas.properties

security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
group.id=test-consumer-group
max.partition.fetch.bytes=10485780


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值