# org.apache.kafka.common.errors.RecordTooLargeException: 请求包含的消息大于服务器将接受的最大消息大小。

- **ID:** `kafka/max-message-bytes-exceeded`
- **领域:** kafka
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

生产者发送的消息超过了代理的 max.message.bytes 或主题的 max.message.bytes 配置，导致代理拒绝该消息。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 2.8.0 | active | — | — |
| Kafka 3.0.0 | active | — | — |
| Kafka 3.4.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |

## 解决方案

1. ```
   Increase the broker's max.message.bytes in server.properties and the topic's max.message.bytes if overridden:

# server.properties
max.message.bytes=10485760  # 10 MB

# Topic override
alter topic my_topic --config max.message.bytes=10485760

Also increase the producer's max.request.size to match:
Properties props = new Properties();
props.put("max.request.size", 10485760);
   ```
2. ```
   Split large messages into smaller chunks at the application level before sending, and reassemble on the consumer side. For example, use a message chunking library or implement custom logic.
   ```

## 无效尝试

- **Increase the producer's max.request.size only** — max.request.size controls the client-side buffer, but the broker's max.message.bytes still blocks the message; both must be increased. (80% 失败率)
- **Set the message compression to gzip** — Compression reduces size but does not guarantee the compressed message will be under the limit; large uncompressed data may still exceed it. (70% 失败率)
