I get Message size too large
exception, when I try to send a message which is over 1 Mb size. The error appears in my client application, when I try to produce a message. After a little googling I found out that the settings should be changed in order to increase max message size. Well, I did that in /kafka/config/server.properties
file. I added next 2 settings:
message.max.bytes=15728640
replica.fetch.max.bytes=15728640
Also, I added fetch.message.max.bytes=15728640
to the /kafka/config/consumer.properties
file. All other settings remain default.
I did kafka server restart, but I'm still getting the same error.
P.S Kafka version is 1.1.0.
Kafka Broker ConfigurationAn optional configuration property, “message. max. bytes“, can be used to allow all topics on a Broker to accept messages of greater than 1MB in size. And this holds the value of the largest record batch size allowed by Kafka after compression (if compression is enabled).
The Kafka max message size is 1MB. In this lesson we will look at two approaches for handling larger messages in Kafka. Kafka has a default limit of 1MB per message in the topic. This is because very large messages are considered inefficient and an anti-pattern in Apache Kafka.
RecordTooLargeException: The message is 1740572 bytes when serialized which is larger than 1048576, which is the value of the max. request. size configuration.
You have the right configuration however you need to also set max.request.size on the producer side.
props.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, 15728640);
max.request.size The maximum size of a request in bytes. This setting will limit the number of record batches the producer will send in a single request to avoid sending huge requests. This is also effectively a cap on the maximum record batch size.
On the Broker side, you have already configured the below parameter that should work
message.max.bytes The largest record batch size allowed by Kafka.
replica.fetch.max.bytes The number of bytes of messages to attempt to fetch for each partition. This is not an absolute maximum if the first record batch in the first non-empty partition of the fetch is larger than this value, the record batch will still be returned to ensure that progress can be made. The maximum record batch size accepted by the broker is defined via message.max.bytes (broker config) or max.message.bytes (topic config).
On the topic side max.message.bytes which is not required in case you have already set message.max.bytes in the broker side
max.message.bytes - this is the largest size of the message the broker will allow being appended to the topic. This size is validated pre-compression. (Defaults to broker's message.max.bytes.)
Refrence https://kafka.apache.org/documentation/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With