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