# 记录批次过大异常：请求包含的记录批次大小超过允许的最大值

- **ID:** `kafka/record-batch-too-large`
- **领域:** kafka
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

单个记录批次大小超过代理的 max.message.bytes 或 message.max.bytes 配置。

## 解决方案

1. ```
   在代理上增加 max.message.bytes：kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-default --alter --add-config 'message.max.bytes=20971520'
   ```
2. ```
   在生产者上减少 batch.size 以限制批次大小：props.put("batch.size", "16384");
   ```
3. ```
   在发送到Kafka之前将大记录拆分为较小的记录。
   ```

## 无效尝试

- **** — Increasing max.request.size on the producer without also increasing broker limits will still cause rejection. (85% 失败率)
- **** — Compressing the batch may not reduce size enough if individual records are too large. (70% 失败率)
