# MQTT CONNACK 返回 0x03（连接被拒绝：服务器不可用），原因是发布数据包过大

- **ID:** `communication/mqtt-publish-too-large`
- **领域:** communication
- **类别:** protocol_error
- **错误码:** `0x03`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

MQTT 代理拒绝了有效载荷超过 CONNACK 中指定的“最大数据包大小”或代理默认限制（通常为 256 KB）的 PUBLISH 数据包。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Mosquitto 2.0.18 | active | — | — |
| EMQX 5.6 | active | — | — |
| HiveMQ 4.27 | active | — | — |
| AWS IoT Core MQTT 2024-03 | active | — | — |

## 解决方案

1. ```
   Configure the broker to increase the maximum packet size. For Mosquitto, set `max_packet_size` in mosquitto.conf. For EMQX, set `mqtt.max_packet_size` in emqx.conf.
   ```
2. ```
   Split large payloads into multiple smaller PUBLISH messages on the client side, and reassemble on the subscriber using a topic-specific convention (e.g., chunked/ prefix).
   ```
3. ```
   Enable MQTT v5.0 and negotiate the maximum packet size during CONNECT by setting the `Maximum Packet Size` property to a value acceptable to both client and broker.
   ```

## 无效尝试

- **Increase the broker's memory limit** — The error is about packet size limits, not memory. More memory doesn't raise the maximum allowed packet size. (90% 失败率)
- **Disable QoS 2 on the publisher** — QoS level doesn't affect the maximum packet size; even QoS 0 messages are subject to the same limit. (85% 失败率)
- **Use a different MQTT client library** — The limit is enforced by the broker, not the client. A different library won't bypass the broker's restriction. (95% 失败率)
