{"record":{"id":"b6c7a2abef911a9e","repo":"openimsdk/open-im-server","slug":"topic-s-groupid-not-found","errorCode":null,"errorMessage":"topic %s groupID not found","messagePattern":"topic (.+?) groupID not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mqbuild/builder.go","lineNumber":170,"sourceCode":"\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":152,"sourceCodeEnd":174,"githubUrl":"https://github.com/openimsdk/open-im-server/blob/175a7bb0673eca18e9d1b10bff4f728da6b1b513/pkg/mqbuild/builder.go#L152-L174","documentation":"GetTopicConsumer resolves a logical topic name to its real Kafka topic and an associated consumer group ID via two internal maps. This error is thrown when the topic exists in logicalTopic but has no entry in topicGroupID, meaning the builder registered the topic mapping without ever recording a consumer group for it. It signals an inconsistent internal registration state rather than a Kafka-side problem.","triggerScenarios":"Calling GetTopicConsumer(ctx, topic) for a topic that was added to logicalTopic (e.g. via a builder registration step) but whose group ID was never set in topicGroupID — typically when topic registration and group registration are done in separate calls and only the first ran, or the group ID was cleared/never configured for that topic.","commonSituations":"Partial configuration: a topic is declared in config but the consumer-group section for it is missing or misnamed; a builder was constructed programmatically where RegisterTopic was called without the corresponding group registration; refactor or version change where group IDs moved to a new map and legacy init code no longer populates it.","solutions":["Check how the builder populates topicGroupID and ensure the registration path for this topic also sets its consumer group ID before GetTopicConsumer is called.","Verify your configuration includes a consumer group for every topic registered; fix or add the missing group entry.","Log both maps (logicalTopic, topicGroupID) at startup and diff them to find the topic missing a group.","As a defensive measure in your own code, validate the topic/group pair against your config before calling GetTopicConsumer.","If the group is genuinely optional, change the builder to derive a default groupID (e.g. topic + \"-group\") instead of erroring."],"exampleFix":"// before (builder init)\nbuilder.RegisterTopic(\"chat\")\n// group registration forgotten\n\n// after\nbuilder.RegisterTopic(\"chat\")\nbuilder.SetGroupID(\"chat\", \"chat-consumer-group\") // populates topicGroupID[realTopic]","handlingStrategy":"validation","validationCode":"func topicReady(b *mqbuild.Builder, topic string) bool {\n\treal, ok := b.LogicalTopic(topic) // or reflect/inspect your registration API\n\treturn ok && b.HasGroupID(real)\n}\nif !topicReady(builder, \"chat\") {\n\treturn fmt.Errorf(\"topic %q has no consumer group configured\", \"chat\")\n}\n_, err := builder.GetTopicConsumer(ctx, \"chat\")","typeGuard":"func hasConsumerGroup(realTopic string, groups map[string]string) bool {\n\t_, ok := groups[realTopic]\n\treturn ok\n}","tryCatchPattern":"cons, err := builder.GetTopicConsumer(ctx, topic)\nif err != nil {\n\tif strings.Contains(err.Error(), \"groupID not found\") {\n\t\t// fall back: re-register group or surface config error\n\t\treturn fmt.Errorf(\"misconfigured topic %s: %w\", topic, err)\n\t}\n\treturn err\n}","preventionTips":["Register topic and consumer group in a single builder method so they can never diverge.","Validate at startup that every entry in logicalTopic has a matching topicGroupID entry and fail fast.","Keep topic/group definitions in one config section and generate both maps from it.","Add a unit test that iterates all registered topics and calls GetTopicConsumer."],"tags":["kafka","consumer-group","configuration","mq"],"backgroundTag":"consumer-group-not-found","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"}