kafka-kafka.common.errors.RecordTooLargeException,kafka.common.MessageSizeTooLargeException

原文鏈接:http://blog.51cto.com/10120275/1844461

1、向Kafka中輸入數據,拋異常

WARN async.DefaultEventHandler: Produce request with correlation id 92548048 failed due to [TopicName,1]: org.apache.kafka.common.errors.RecordTooLargeException

官網兩個參數描述如下:

message.max.bytes The maximum size of message that the server can receive int 1000012 [0,...] high
fetch.message.max.bytes 1024 * 1024 The number of byes of messages to attempt to fetch for each topic-partition in each fetch request. These bytes will be read into memory for each partition, so this helps control the memory used by the consumer. The fetch request size must be at least as large as the maximum message size the server allows or else it is possible for the producer to send messages larger than the consumer can fetch.

message.max.bytes:server能接受消息體的最大值。

fetch.message.max.bytes:consumer從partition中獲取消息體放入內存中,這個參數控制conusmer所用的內存大小。如果message.max.bytes大於fetch.message.max.bytes,就會導致consumer分配的內存放不下一個message。

因此,在server.properties中添加配置項

1

2

3

4

#broker能接收消息的最大字節數

message.max.bytes=20000000

#broker可複製的消息的最大字節數

fetch.message.max.bytes=20485760

如果不想修改配置文件,可以採用修改topic配置的方法,與server配置項message.max.bytes對應的topic配置項是max.message.bytes

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic my-topic
    --config max.message.bytes=128000

注意:需要修改所有節點的配置文件並且重啓kafka,這樣重新選舉主節點的時候能夠讀取最新的配置文件,並且在以後主節點切換的時候讀取的配置文件都是同一個配置。

2、讀取Kafka中數據,有異常

 

kafka.common.MessageSizeTooLargeException: Found a message larger than the maximum fetch size of this consumer on topic TopicName partition 0 at fetch offset 42057452. Increase the fetch size, or decrease the maximum message size the broker will allow.

這個與Kafka消費者的參數fetch.message.max.bytes有關,

在增加message.max.bytes之後,表示進入Kafka消息體變大,此時控制消費者接受消息大小的參數也要有相應變化,

我使用Flume讀取Kafka中消息,從而我Flume Agent的配置文件中會有如下配置

consumer.sources.sourcename.kafka.fetch.message.max.bytes=20485760

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章