Kafka 整个消息管道的默认口径是 1M,换句话说,默认 Producer 只能向 Kafka 发送大小不超过 1M 的消息,Kafka 内部也只能处理大小不超过 1M 的消息,Consumer 也只能消费大小不超过 1M 的消息。
如果发送 2M(为了方便计算,以下 1M=1000K)大小的数据,client 会报异常
1
Exception in thread "main" java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.RecordTooLargeException: The message is 2000037 bytes when serialized which is larger than the maximum request size you have configured with the max.request.size configuration.
根据提示,在 Producer config 中设置 max.request.size 为 2M+(注意必须大于 2M,因为消息本身的 metadata 也会占用空间,比如上文日志中,一条包含 2M 数据的消息的大小是 2M+37 byte),但服务器返回异常
1
Exception in thread "main" java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.
服务器无法接收这么大的