Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Set different authentication mechanisms on consumers and producers directly #568

Open
MartinCarpMBC opened this issue May 11, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@MartinCarpMBC
Copy link

Is your request related to a problem you have?

We use eventhub with a kafka connector using a different authentication mechanism on the consumer side, and use a kafka producer towards confluent kafka on the other side.

Describe the solution you'd like

Make it possible to set authentication directly on consumer and producer to overwrite the default overall authentication.

Are you able to help bring it to life and contribute with a Pull Request?

Yes

Additional context

No response

@MartinCarpMBC MartinCarpMBC added the enhancement New feature or request label May 11, 2024
@joelfoliveira
Copy link
Contributor

Hi @MartinCarpMBC ,

You should be able to override the Producer and Consumer auth settings using the WithProducerConfig and WithConsumerConfig methods when configuring the producers and consumers.

example:

services.AddKafka(
    kafka => kafka
        .AddCluster(
            cluster => cluster
                .WithBrokers(new[] { "localhost:9092" })
                .CreateTopicIfNotExists(topicName, 6, 1)
                .AddProducer(
                    producerName,
                    producer => producer
                        .DefaultTopic(topicName)
                        .WithProducerConfig(new ProducerConfig
                        {
                            SaslUsername = "user",
                            SaslPassword = "pass",
                            SaslMechanism = SaslMechanism.Plain,
                            SecurityProtocol = SecurityProtocol.Plaintext,
                            EnableSslCertificateVerification = true
                        })
                        .AddMiddlewares(m => m.AddSerializer<ProtobufNetSerializer>())
                )
                .AddConsumer(
                    consumer => consumer
                        .Topic(topicName)
                        .WithGroupId("consumer-group-1")
                        .WithConsumerConfig(new ConsumerConfig
                        {
                            SaslUsername = "otheruser",
                            SaslPassword = "otherpass",
                            SaslMechanism = SaslMechanism.Plain,
                            SecurityProtocol = SecurityProtocol.Plaintext,
                            EnableSslCertificateVerification = true
                        })
                        .AddMiddlewares(
                            middlewares => middlewares
                                .AddDeserializer<ProtobufNetDeserializer>()
                        ))));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants