apache/kafka · error · org.apache.kafka.common.config.ConfigException

{} cannot be set when using a share group.

Error message

{} cannot be set when using a share group.

What it means

ConfigException thrown by ShareConsumerConfig when any config key in SHARE_GROUP_UNSUPPORTED_CONFIGS is present while constructing a share-group consumer. Share groups use server-side acknowledgment instead of consumer-side assignment/commit, so these classic consumer options (auto.offset.reset, enable.auto.commit, group.instance.id, isolation.level, partition.assignment.strategy, interceptor.classes, session.timeout.ms, heartbeat.interval.ms, group.protocol, group.remote.assignor) are rejected up front.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/consumer/ShareConsumerConfig.java:72

    protected ShareConsumerConfig(Map<?, ?> props, boolean doLog) {
        super(props, doLog);
    }

    @Override
    protected Map<String, Object> preProcessParsedConfig(final Map<String, Object> parsedValues) {
        checkUnsupportedConfigsPreProcess(parsedValues);
        return parsedValues;
    }

    private void checkUnsupportedConfigsPreProcess(Map<String, Object> parsedValues) {
        List<String> invalidConfigs = new ArrayList<>();
        SHARE_GROUP_UNSUPPORTED_CONFIGS.forEach(configName -> {
            if (parsedValues.containsKey(configName)) {
                invalidConfigs.add(configName);
            }
        });
        if (!invalidConfigs.isEmpty()) {
            throw new ConfigException(String.join(", ", invalidConfigs) +
                    " cannot be set when using a share group.");
        }
    }

    @Override
    protected void checkUnsupportedConfigsPostProcess() {
    }
}

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Remove the listed keys from the share consumer config (auto.offset.reset, enable.auto.commit, group.instance.id, isolation.level, partition.assignment.strategy, interceptor.classes, session.timeout.ms, heartbeat.interval.ms, group.protocol, group.remote.assignor).
  2. Keep a separate config template for share consumers vs classic consumers.
  3. If the same Properties object must be shared, strip unsupported keys before constructing the share consumer.

Example fix

// before
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
props.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, "org.apache.kafka.clients.consumer.CooperativeStickyAssignor");
props.put(ConsumerConfig.GROUP_PROTOCOL_CONFIG, "consumer");
try (KafkaConsumer<Void, Void> c = new KafkaConsumer<>(props)) { ... } // share group

// after
props.remove(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG);
props.remove(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG);
props.remove(ConsumerConfig.GROUP_PROTOCOL_CONFIG);
try (KafkaConsumer<Void, Void> c = new KafkaConsumer<>(props)) { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Filter out share-group-incompatible keys before constructing ShareConsumer / ShareConsumerConfig
Set<String> SHARE_GROUP_UNSUPPORTED = Set.of(
    ConsumerConfig.GROUP_ID_CONFIG,
    ConsumerConfig.GROUP_INSTANCE_ID_CONFIG,
    ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG,
    ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
    ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
    ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG
);
Map<String, Object> safeProps = new HashMap<>(props);
List<String> offending = SHARE_GROUP_UNSUPPORTED.stream()
    .filter(safeProps::containsKey).collect(Collectors.toList());
if (!offending.isEmpty()) {
    throw new ConfigException(offending + " cannot be set when using a share group.");
}
new KafkaShareConsumer<>(safeProps, keyDeser, valDeser);

Try / catch

try {
    new KafkaShareConsumer<>(props, keyDeser, valDeser);
} catch (ConfigException e) {
    if (e.getMessage() != null && e.getMessage().contains("cannot be set when using a share group")) {
        // remove the offending keys listed in the message and retry construction
    }
    throw e;
}

Prevention

When it happens

Trigger: Building a KafkaConsumer in SHARE group protocol with any of the unsupported keys set in the Properties/Map; reusing a regular consumer config verbatim for a share consumer.

Common situations: Promoting an existing consumer config to share-group usage without pruning incompatible options; copy-pasted config from a non-share consumer tutorial; version mismatch where share-group support was added but legacy keys were left in.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/6a94b568c0e6b180.json. Report an issue: GitHub.