diff --git a/docs/src/main/asciidoc/kafka.adoc b/docs/src/main/asciidoc/kafka.adoc index f93a2127a65323..7333ded9a5ae1b 100644 --- a/docs/src/main/asciidoc/kafka.adoc +++ b/docs/src/main/asciidoc/kafka.adoc @@ -915,7 +915,11 @@ Type: _string_ | true | Type: _int_ | false | `1` -| *group.id* | A unique string that identifies the consumer group the application belongs to. If not set, a unique, generated id is used +| *group.id* | A unique string that identifies the consumer group the application belongs to. + +If not set, defaults to the application name as set by the `quarkus.application.name` configuration property. + +If that is not set either, a unique, generated id is used. Type: _string_ | false | diff --git a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java index 933c318849f7d4..dd5ad8d6801a49 100644 --- a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java +++ b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/KafkaRuntimeConfigProducer.java @@ -13,32 +13,40 @@ import org.eclipse.microprofile.config.ConfigProvider; import io.quarkus.arc.DefaultBean; +import io.quarkus.runtime.ApplicationConfig; @Dependent public class KafkaRuntimeConfigProducer { - private String configPrefix = "kafka"; + // not "kafka.", because we also inspect env vars, which start with "KAFKA_" + private static final String CONFIG_PREFIX = "kafka"; + + private static final String GROUP_ID = "group.id"; @Produces @DefaultBean @ApplicationScoped @Named("default-kafka-broker") - public Map createKafkaRuntimeConfig() { + public Map createKafkaRuntimeConfig(ApplicationConfig app) { Map properties = new HashMap<>(); final Config config = ConfigProvider.getConfig(); StreamSupport .stream(config.getPropertyNames().spliterator(), false) .map(String::toLowerCase) - .filter(name -> name.startsWith(configPrefix)) + .filter(name -> name.startsWith(CONFIG_PREFIX)) .distinct() .sorted() .forEach(name -> { - final String key = name.substring(configPrefix.length() + 1).toLowerCase().replaceAll("[^a-z0-9.]", "."); + final String key = name.substring(CONFIG_PREFIX.length() + 1).toLowerCase().replaceAll("[^a-z0-9.]", "."); final String value = config.getOptionalValue(name, String.class).orElse(""); properties.put(key, value); }); + if (!properties.containsKey(GROUP_ID) && app.name.isPresent()) { + properties.put(GROUP_ID, app.name.get()); + } + return properties; }