{"record":{"id":"554eaca792adc036","repo":"apache/rocketmq","slug":"the-specified-topic-is-longer-than-topic-max-lengt","errorCode":null,"errorMessage":"The specified topic is longer than topic max length %d.","messagePattern":"The specified topic is longer than topic max length (.+?)\\.","errorType":"validation","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/Validators.java","lineNumber":101,"sourceCode":"        if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {\n            throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,\n                \"the message body size over max value, MAX: \" + defaultMQProducer.getMaxMessageSize());\n        }\n\n        String lmqPath = msg.getUserProperty(MessageConst.PROPERTY_INNER_MULTI_DISPATCH);\n        if (StringUtils.contains(lmqPath, File.separator)) {\n            throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,\n                \"INNER_MULTI_DISPATCH \" + lmqPath + \" can not contains \" + File.separator + \" character\");\n        }\n    }\n\n    public static void checkTopic(String topic) throws MQClientException {\n        if (UtilAll.isBlank(topic)) {\n            throw new MQClientException(\"The specified topic is blank\", null);\n        }\n\n        if (topic.length() > TOPIC_MAX_LENGTH) {\n            throw new MQClientException(\n                String.format(\"The specified topic is longer than topic max length %d.\", TOPIC_MAX_LENGTH), null);\n        }\n\n        if (isTopicOrGroupIllegal(topic)) {\n            throw new MQClientException(String.format(\n                    \"The specified topic[%s] contains illegal characters, allowing only %s\", topic,\n                    \"^[%|a-zA-Z0-9_-]+$\"), null);\n        }\n    }\n\n    public static void isSystemTopic(String topic) throws MQClientException {\n        if (TopicValidator.isSystemTopic(topic)) {\n            throw new MQClientException(\n                    String.format(\"The topic[%s] is conflict with system topic.\", topic), null);\n        }\n    }\n\n    public static void isNotAllowedSendTopic(String topic) throws MQClientException {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/Validators.java#L83-L119","documentation":"Validators.checkTopic rejects topics longer than TOPIC_MAX_LENGTH (127 characters). Topic length is capped because it is stored in the broker's topic config and appears in commit-log/message-queue metadata; the constant is shared with TopicValidator.","triggerScenarios":"Programmatically building a topic from a template (app + env + tenant + event type) whose concatenation exceeds 127 chars; dynamic per-entity topics with UUID suffixes.","commonSituations":"Multi-tenant systems minting one topic per tenant with long tenant identifiers; namespaced topic conventions ported from systems without length limits.","solutions":["Shorten the topic to <=127 characters using abbreviations or a tenant-id mapping table.","Hash long suffixes and keep the readable prefix within budget.","Assert topic.length() <= 127 in the topic-factory code path."],"exampleFix":"// before\nString topic = \"evt-\" + tenantId + '-' + UUID.randomUUID(); // can exceed 127\n\n// after\nString topic = \"evt-\" + tenantId + '-' + shortHash(tenantId); // bounded length","handlingStrategy":"validation","validationCode":"static boolean topicLengthOk(String topic) {\n    return topic != null && topic.length() <= 127;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound generated topic names in a factory method with a length assertion.","Map long tenant identifiers to short codes before composing topics."],"tags":["rocketmq","topic","validation","length-limit"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}