RocketMQ-Topic命名规则

  1. 不能为空

  2. 只能包含%数字大小写字母及下划线和中划线

  3. 长度不能超过255个字符(在broker中限制却是127),以broker为主

    在4.6.1版本中已经统一为127

  4. 不能与默认用于判断是否可自动创建topic(TBW102)重名

public class Validators {
	public static void checkTopic(String topic) throws MQClientException {
    if (UtilAll.isBlank(topic)) {
        throw new MQClientException("The specified topic is blank", null);
    }

    //public static final String VALID_PATTERN_STR = "^[%|a-zA-Z0-9_-]+$";
    if (!regularExpressionMatcher(topic, PATTERN)) {
        throw new MQClientException(String.format(
            "The specified topic[%s] contains illegal characters, allowing only %s", topic,
            VALID_PATTERN_STR), null);
    }

    //在4.6.1版本中已经统一为127
    if (topic.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("The specified topic is longer than topic max length 255.", null);
    }

    //whether the same with system reserved keyword
    //public static final String AUTO_CREATE_TOPIC_KEY_TOPIC = "TBW102";
    if (topic.equals(MixAll.AUTO_CREATE_TOPIC_KEY_TOPIC)) {
        throw new MQClientException(
            String.format("The topic[%s] is conflict with AUTO_CREATE_TOPIC_KEY_TOPIC.", topic), null);
    }
}
}

DefaultMessageStore 实际存储消息的时候还有检测,Byte.MAX_VALUE=127
if (msg.getTopic().length() > Byte.MAX_VALUE) {
    log.warn("putMessage message topic length too long " + msg.getTopic().length());
    return new PutMessageResult(PutMessageStatus.MESSAGE_ILLEGAL, null);
}
  1. 大小写敏感

TOPIC

Topic

是两个不同的topic

你可能感兴趣的:(RocketMQ)