1. RocketMQ在消息发送时需要对消息的长度进行校验:
    1. 不为空
    2. 长度不为0
    3. 最大长度不能超过1024 1024 4字节,也就是4M ```java //消息不能为空 if (null == msg) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, “the message is null”); } // 检查Topic:不为空,不为异常格式,长度不能大于127 Validators.checkTopic(msg.getTopic()); //检查当前Topic:不能在黑名单中 Validators.isNotAllowedSendTopic(msg.getTopic());

    // 消息体不为空 if (null == msg.getBody()) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, “the message body is null”); } //长度不为0 if (0 == msg.getBody().length) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, “the message body length is zero”); } //最大长度不能超过4M if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, “the message body size over max value, MAX: “ + defaultMQProducer.getMaxMessageSize()); } ```