{"record":{"id":"b78cb4a37fd168dd","repo":"t8y2/dbx","slug":"no-rocketmq-master-broker-found-for-topic-s-b78cb4","errorCode":null,"errorMessage":"no RocketMQ master broker found for topic %s","messagePattern":"no RocketMQ master broker found for topic (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rocketmq/messages.go","lineNumber":240,"sourceCode":"\tconnectTimeout time.Duration,\n\ttopic string,\n\tkey string,\n\tmaxNum int,\n\tbeginTimestamp int64,\n\tendTimestamp int64,\n) ([]*admin.MessageExt, error) {\n\troute, err := client.ExamineTopicRouteInfo(ctx, topic)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttargets := make([]messageQueueTarget, 0, len(route.BrokerDatas))\n\tfor _, broker := range route.BrokerDatas {\n\t\tif address := broker.BrokerAddrs[\"0\"]; address != \"\" {\n\t\t\ttargets = append(targets, messageQueueTarget{BrokerName: broker.BrokerName, Address: address})\n\t\t}\n\t}\n\tif len(targets) == 0 {\n\t\treturn nil, fmt.Errorf(\"no RocketMQ master broker found for topic %s\", topic)\n\t}\n\tmessages := make([]*admin.MessageExt, 0)\n\tsuccessCount := 0\n\tvar lastErr error\n\tfor _, target := range targets {\n\t\tresponse, requestErr := invokeRemotingAllowCodes(ctx, target.Address, connectTimeout,\n\t\t\tbuildQueryMessageCommand(topic, key, maxNum, beginTimestamp, endTimestamp),\n\t\t\tremoting.Success, queryMessageNotFoundCode)\n\t\tif requestErr != nil {\n\t\t\tlastErr = requestErr\n\t\t\tcontinue\n\t\t}\n\t\tsuccessCount++\n\t\tif response.Code == queryMessageNotFoundCode || len(response.Body) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tfor _, message := range primitive.DecodeMessage(response.Body) {\n\t\t\tqueueID := 0","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rocketmq/messages.go#L222-L258","documentation":"queryMessagesByKey resolves the topic route via ExamineTopicRouteInfo and collects only broker addresses registered under brokerId '0' (the master). If the topic's route has no BrokerData entry with a non-empty master address, the library cannot query any broker and returns this error. It means the topic route exists but has no usable master broker endpoint.","triggerScenarios":"Calling viewMessage or queryMessageByKey (message-by-key lookup or message-trace query) when the topic's route from the NameServer lists BrokerDatas whose BrokerAddrs map lacks the '0' key, has an empty '0' value, or only contains slave broker IDs.","commonSituations":"Master broker down and deregistered while the NameServer still returns the topic route; broker running with brokerId != 0; stale route left after a broker was removed; NameServer holding cached route info after a broker crash.","solutions":["Verify with mqadmin clusterList/brokerStatus that a master broker (brokerId=0) for the topic's group is running and registered.","Set brokerId=0 in the master's broker.conf (slaves use 1+).","Check brokerIP1/brokerListenPort resolve to an address reachable by the client.","If the route is stale, recreate the topic: mqadmin deleteTopic then mqadmin updateTopic.","Restart the master broker so it re-registers with the NameServer."],"exampleFix":"// before\nbrokerId = 1\n// after (on the intended master)\nbrokerId = 0","handlingStrategy":"validation","validationCode":"// Resolve route and check for a master (brokerId \"0\") before querying.\nroute, err := client.ExamineTopicRouteInfo(ctx, topic)\nif err != nil { return err }\nhasMaster := false\nfor _, bd := range route.BrokerDatas {\n    if addr, ok := bd.BrokerAddrs[\"0\"]; ok && addr != \"\" { hasMaster = true; break }\n}\nif !hasMaster {\n    return fmt.Errorf(\"topic %s has no master broker; run: mqadmin clusterList\", topic)\n}","typeGuard":"func hasMasterBroker(route *admin.TopicRoute) bool {\n    for _, bd := range route.BrokerDatas {\n        if addr, ok := bd.BrokerAddrs[\"0\"]; ok && addr != \"\" {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Monitor master broker liveness and NameServer registration (mqadmin clusterList) with alerts.","Pin brokerId=0 in the master broker.conf and validate broker groups after topology changes.","Run health checks over the same network path the client uses.","Delete stale topics after removing brokers so routes don't dangle."],"tags":["rocketmq","routing","broker","nameserver"],"backgroundTag":"no-broker-route","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}