Home > OS >  Kafka Dotnet Builders best practices
Kafka Dotnet Builders best practices

Time:05-10

I am using dotnet to build a Kafka application and I found that this NuGet package from Confluent.

The documentation is okay, but I was wondering the following: I have a controller, and I will receive multiple requests, where I will use a producer to insert data into a Kafka topic. But I'm not sure what to do with the ProducerBuilder class. Should I create a producer on each request, or just a producer per the lifetime of the app? What are the pros & cons?

CodePudding user response:

Producer instances should only be created once, per unique producer configuration. One instance can write to many topics. You need a builder to get the instance.

You should be able to inject a built Producer into your Service/Controller classes rather than needing to rebuild one on each request.

  • Related