RocketMQ-Topic命名规则

RocketMQ的Topic命名有特定规则,包括字符限制在127个,仅允许数字、字母、下划线和中划线,并且不能与默认的TBW102标识符重名,区分大小写。了解这些规则对于正确操作RocketMQ至关重要。
  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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值