{"id":"962ff6d4b9064ff5","repo":"apache/kafka","slug":"you-must-provide-a-valid-consumerconfig-group-id","errorCode":null,"errorMessage":"You must provide a valid ${ConsumerConfig.GROUP_ID_CONFIG} in the consumer configuration.","messagePattern":"You must provide a valid (.+?) in the consumer configuration\\.","errorType":"exception","errorClass":"InvalidGroupIdException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumerImpl.java","lineNumber":1173,"sourceCode":"        }\n        refCount.incrementAndGet();\n    }\n\n    /**\n     * Release the light lock protecting the consumer from multithreaded access.\n     */\n    private void release() {\n        if (refCount.decrementAndGet() == 0)\n            currentThread.set(NO_CURRENT_THREAD);\n    }\n\n    public static LogContext createLogContext(final String clientId, final String groupId) {\n        return new LogContext(\"[ShareConsumer clientId=\" + clientId + \", groupId=\" + groupId + \"] \");\n    }\n\n    private void maybeThrowInvalidGroupIdException() {\n        if (groupId == null || groupId.isEmpty()) {\n            throw new InvalidGroupIdException(\n                    \"You must provide a valid \" + ConsumerConfig.GROUP_ID_CONFIG + \" in the consumer configuration.\");\n        }\n    }\n\n    /**\n     * Handles any completed acknowledgements. If there is an acknowledgement commit callback registered,\n     * call it. Otherwise, discard the information about completed acknowledgements because the application\n     * is not interested.\n     */\n    private void handleCompletedAcknowledgements() {\n        if (acknowledgementEventQueue == null || acknowledgementEventHandler == null) {\n            return;\n        }\n\n        processAcknowledgementEvents();\n\n        if (!completedAcknowledgements.isEmpty()) {\n            try {","sourceCodeStart":1155,"sourceCodeEnd":1191,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumerImpl.java#L1155-L1191","documentation":"Thrown by maybeThrowInvalidGroupIdException() (line 1173) as InvalidGroupIdException when groupId is null or empty. The share consumer mandates a group.id because share-group membership is what the broker uses to assign and track delivery of records to this consumer. It is checked in the constructor (line 251) and again in subscribe() (line 550), so both eager and lazy usage fail fast.","triggerScenarios":"Constructing KafkaShareConsumer with a properties map missing group.id, or with group.id set to an empty string. Also reached when subscribe(...) is called on a consumer whose group.id resolved to null via a ConfigProvider that returned no value.","commonSituations":"Share-consumer quickstart that copies a regular consumer example but omits group.id; Spring Boot @ConfigurationProperties binding that did not map the group.id property; templated config where ${KAFKA_GROUP} was unset and expanded to empty; multiple consumer beans sharing a base config where the group.id override was forgotten on one.","solutions":["Set group.id to a non-empty string in the consumer properties: props.put(ConsumerConfig.GROUP_ID_CONFIG, \"order-share-group\").","If using Spring/Quarkus, ensure @Value or @ConfigurationProperties actually resolves the property and is not blank.","Validate required config at startup — fail the application context if group.id is missing rather than letting the consumer throw later.","For multiple share groups, instantiate one consumer per group, each with its own distinct group.id."],"exampleFix":"// before\nprops.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers);\nnew KafkaShareConsumer<String,String>(props);\n\n// after\nprops.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers);\nprops.put(ConsumerConfig.GROUP_ID_CONFIG, \"order-share-group\");\nnew KafkaShareConsumer<String,String>(props);","handlingStrategy":"validation","validationCode":"// Validate group.id before constructing the ShareConsumer.\nString groupId = (String) props.get(org.apache.kafka.clients.consumer.ConsumerConfig.GROUP_ID_CONFIG);\nif (groupId == null || groupId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\n        \"ShareConsumer requires a non-empty \" + org.apache.kafka.clients.consumer.ConsumerConfig.GROUP_ID_CONFIG);\n}\nnew org.apache.kafka.clients.consumer.KafkaShareConsumer<>(props, keyDeser, valueDeser);","typeGuard":"null","tryCatchPattern":"try {\n    consumer = new org.apache.kafka.clients.consumer.KafkaShareConsumer<>(props, keyDeser, valueDeser);\n} catch (org.apache.kafka.common.errors.InvalidGroupIdException e) {\n    // configuration error: fix group.id and rebuild props before retrying\n    props.put(org.apache.kafka.clients.consumer.ConsumerConfig.GROUP_ID_CONFIG, requiredGroupId);\n    throw e;\n}","preventionTips":["Share consumption always requires a group.id; set it once in a central config builder.","Fail fast at startup by asserting group.id is present rather than discovering it on first poll.","Do not reuse a properties object that previously had group.id removed for another use case."],"tags":["share-consumer","config","group-id","kafka-client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}