{"record":{"id":"6002fd718fbb502c","repo":"t8y2/dbx","slug":"query-messages-for-topic-s-on-all-masters-w","errorCode":null,"errorMessage":"query messages for topic %s on all masters: %w","messagePattern":"query messages for topic (.+?) on all masters: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rocketmq/messages.go","lineNumber":277,"sourceCode":"\t\t\tif message.Queue != nil {\n\t\t\t\tqueueID = message.Queue.QueueId\n\t\t\t}\n\t\t\tmessageTopic := message.Topic\n\t\t\tif messageTopic == \"\" {\n\t\t\t\tmessageTopic = topic\n\t\t\t}\n\t\t\tmessages = append(messages, &admin.MessageExt{\n\t\t\t\tTopic: messageTopic, QueueId: queueID, QueueOffset: message.QueueOffset,\n\t\t\t\tMsgId: message.MsgId, OffsetMsgId: message.OffsetMsgId, Body: message.Body,\n\t\t\t\tFlag: int(message.Flag), BornTimestamp: message.BornTimestamp,\n\t\t\t\tStoreTimestamp: message.StoreTimestamp, BornHost: message.BornHost,\n\t\t\t\tStoreHost: message.StoreHost, SysFlag: int(message.SysFlag),\n\t\t\t\tBrokerName: target.BrokerName, Properties: message.GetProperties(),\n\t\t\t})\n\t\t}\n\t}\n\tif successCount == 0 {\n\t\treturn nil, fmt.Errorf(\"query messages for topic %s on all masters: %w\", topic, lastErr)\n\t}\n\treturn messages, nil\n}\n\nfunc buildQueryMessageCommand(topic, key string, maxNum int, beginTimestamp, endTimestamp int64) *remoting.RemotingCommand {\n\treturn remoting.NewRequest(remoting.QueryMessage, map[string]string{\n\t\t\"topic\": topic, \"key\": key, \"maxNum\": strconv.Itoa(maxNum),\n\t\t\"beginTimestamp\": strconv.FormatInt(beginTimestamp, 10),\n\t\t\"endTimestamp\":   strconv.FormatInt(endTimestamp, 10),\n\t})\n}\n\nfunc (a *rocketMQAgent) queryMessageByTopic(params map[string]any) (any, error) {\n\ttopic, err := requireString(params, \"topic\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tclient, config, _ := a.requireClient()","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rocketmq/messages.go#L259-L295","documentation":"queryMessagesByKey sends a QueryMessage request to every master broker found in the route. If every request fails, successCount stays 0 and the library wraps the last per-broker error with this message. All masters failed to answer the key-based message query.","triggerScenarios":"Calling viewMessage / queryMessageByKey when every master broker request fails due to network errors, timeouts, or remoting rejections — broker down, connection refused, firewall, or unsupported response code.","commonSituations":"Firewall blocking the broker listen port (default 10911); all brokers down while NameServer returns cached routes; connectTimeout too small; TLS/plain-text mismatch; broker overloaded and dropping requests.","solutions":["Inspect the wrapped cause (%w) to identify the actual per-broker failure and fix it first.","Test connectivity: nc -vz <brokerIP> 10911 from the client host.","Increase config.ConnectTimeout / RequestTimeout if brokers are slow or remote.","Confirm masters are alive (mqadmin clusterList) and restart any crashed ones.","If requests are rejected, check broker permissions and that the topic perm includes the READ bit (2, typical value 6)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check that each master address is reachable before issuing the query.\nfor _, bd := range route.BrokerDatas {\n    if addr := bd.BrokerAddrs[\"0\"]; addr != \"\" {\n        conn, err := net.DialTimeout(\"tcp\", hostPort(addr), 2*time.Second)\n        if err != nil { log.Printf(\"master %s unreachable: %v\", bd.BrokerName, err) } else { conn.Close() }\n    }\n}","typeGuard":null,"tryCatchPattern":"msgs, err := queryMessageByKey(params)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        return retryWithBackoff(3, func() error { return queryMessageByKey(params) })\n    }\n    return fmt.Errorf(\"key query failed on all masters: %w\", err)\n}","preventionTips":["Always inspect the wrapped cause (%w) — it names the actual broker failure.","Set ConnectTimeout/RequestTimeout generously for remote or busy clusters.","Keep firewall rules open for broker listen ports (default 10911).","Alert on broker downtime; query-by-key is unavailable while masters are down."],"tags":["rocketmq","network","broker","query"],"backgroundTag":"all-brokers-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}