{"record":{"id":"a2133ad39a440a82","repo":"openimsdk/open-im-server","slug":"topic-s-not-found","errorCode":null,"errorMessage":"topic %s not found","messagePattern":"topic (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mqbuild/builder.go","lineNumber":158,"sourceCode":"func (standaloneBuilder) GetTopicProducer(ctx context.Context, topic string) (mq.Producer, error) {\n\treturn simmq.GetTopicProducer(topic), nil\n}\n\nfunc (standaloneBuilder) GetTopicConsumer(ctx context.Context, topic string) (mq.Consumer, error) {\n\treturn simmq.GetTopicConsumer(topic), nil\n}\n\ntype kafkaBuilder struct {\n\taddr         []string\n\tconfig       *kafka.Config\n\tlogicalTopic map[string]string\n\ttopicGroupID map[string]string\n}\n\nfunc (x *kafkaBuilder) GetTopicProducer(ctx context.Context, topic string) (mq.Producer, error) {\n\trealTopic, ok := x.logicalTopic[topic]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"topic %s not found\", topic)\n\t}\n\treturn kafka.NewKafkaProducerV2(x.config, x.addr, realTopic)\n}\n\nfunc (x *kafkaBuilder) GetTopicConsumer(ctx context.Context, topic string) (mq.Consumer, error) {\n\trealTopic, ok := x.logicalTopic[topic]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"topic %s not found\", topic)\n\t}\n\tgroupID, ok := x.topicGroupID[realTopic]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"topic %s groupID not found\", realTopic)\n\t}\n\treturn kafka.NewMConsumerGroupV2(ctx, x.config, groupID, []string{realTopic}, true)\n}\n","sourceCodeStart":140,"sourceCodeEnd":174,"githubUrl":"https://github.com/openimsdk/open-im-server/blob/175a7bb0673eca18e9d1b10bff4f728da6b1b513/pkg/mqbuild/builder.go#L140-L174","documentation":"kafkaBuilder.GetTopicProducer looks up the logical topic name in its pre-registered logicalTopic map; if the topic was never registered with the builder, it returns 'topic %s not found'. Only topics declared in the Kafka topics config are resolvable.","triggerScenarios":"Calling GetTopicProducer with a topic string that MergeTopics/KafkaTopics did not register — typically a topic missing from the kafka.topics config.","commonSituations":"Code publishes to a new logical topic but ops forgot to add it to config; renamed topic in code without updating config; typo in topic constant.","solutions":["Add the topic to the kafka topics configuration so the builder registers it","Correct the topic name passed to GetTopicProducer","Rebuild/merge topics (MergeTopics) before constructing producers"],"exampleFix":"// before\nkafka:\n  topics: [\"msgToMq\"]\n// after\nkafka:\n  topics: [\"msgToMq\", \"newTopic\"]","handlingStrategy":"validation","validationCode":"func topicRegistered(builder *mqbuild.KafkaBuilderTopics, topic string) bool {\n    for _, t := range cfg.Queue.Kafka.Topics {\n        if t == topic { return true }\n    }\n    return false\n}\nif !topicRegistered(nil, myTopic) {\n    return fmt.Errorf(\"topic %q must be added to kafka.topics config\", myTopic)\n}","typeGuard":null,"tryCatchPattern":"p, err := builder.GetTopicProducer(ctx, topic)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    // fail fast: topic missing from config\n}","preventionTips":["Keep a single source-of-truth topic constant shared by producer and config","Add a startup assert that all referenced topics exist in config","Review topic lists when adding new producers"],"tags":["kafka","messaging","config","topic"],"backgroundTag":"topic-not-registered","analyzedSha":"175a7bb0673eca18e9d1b10bff4f728da6b1b513","analyzedAt":"2026-09-04T16:52:56.821Z","contentChangedAt":"2026-09-04T16:52:56.821Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}