Skip to content

Adds ExtendConsumerConfiguration for KafkaListenerConfiguration - #3034

Merged
jeremydmiller merged 1 commit into
JasperFx:mainfrom
Ferchke7:adds-extending-consumer-configuration
Jun 5, 2026
Merged

jeremydmiller merged 1 commit into
JasperFx:mainfrom
Ferchke7:adds-extending-consumer-configuration

Conversation

@Ferchke7

@Ferchke7 Ferchke7 commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds coverage for topic-level Kafka consumer configuration behavior

This PR adds test coverage for the difference between ConfigureConsumer() and ExtendConsumerConfiguration() on Kafka topic listeners.

ConfigureConsumer() intentionally creates a new topic-level ConsumerConfig and replaces the transport-level consumer configuration. This is useful when a topic needs a completely separate consumer configuration.

ExtendConsumerConfiguration() is intended for the more common case where Kafka client settings are configured globally, and an individual topic only needs to adjust a small number of consumer-specific options without losing the shared configuration.

For example, an application may configure SSL once at the transport level:

kafka.ConfigureClient(config => config.ConfigureClientConfig(settings));

public static class ConfluentKafkaExtensions
{
    public static void ConfigureClientConfig(this ClientConfig config, KafkaSettings settings)
    {
        if (settings.UseSsl)
        {
            config.SecurityProtocol = SecurityProtocol.Ssl;
            config.SslKeystoreLocation = Path.Combine(AppContext.BaseDirectory, settings.Ssl.KeystoreLocation);
            config.SslKeystorePassword = settings.Ssl.KeystorePassword;
            config.SslCaLocation = Path.Combine(AppContext.BaseDirectory, settings.Ssl.SslCaLocation);
            config.SslKeyPassword = settings.Ssl.KeyPassword;
            config.EnableSslCertificateVerification = settings.Ssl.EnableCertificateVerification;
        }
    }
}

Then a specific topic may only need to override the consumer group:

opts.ListenToKafkaTopic("orders")
    .ExtendConsumerConfiguration(config =>
    {
        config.GroupId = "orders-service";
    });

In this case, the topic should keep the shared SSL/client settings while applying the topic-specific consumer setting.

Using ConfigureConsumer() for this scenario would be easy to misuse, because it replaces the topic consumer config entirely:

opts.ListenToKafkaTopic("orders")
    .ConfigureConsumer(config =>
    {
        config.GroupId = "orders-service";
    });

@Ferchke7 Ferchke7 changed the title Adds ExtendConsumerConfiguration for KafkaListenerConfiguration.cs Adds ExtendConsumerConfiguration for KafkaListenerConfiguration Jun 4, 2026
@jeremydmiller
jeremydmiller merged commit 9386d0c into JasperFx:main Jun 5, 2026
23 checks passed
This was referenced Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants