What's the best practice for producer creation in things like web requests?
I believe we should be using one producer for multiple requests, i.e. create a singleton that always provides the same object and going by this question that seems correct?
So say if we have a singleton class that creates a producer with new ProducerBuilder<string, string>(config).Build()
Will the GC be able to handle this or do we need to dispose when app is ending? So if we kill/restart the app, would it leak?
Possibly prematurely worrying here but thought it would be worth asking.
Cheers
suggest creating a lightweight wrapper class around the producer that takes IConfiguration as a constructor argument and sets everything up + is IDisposable. Then add this as a singleton in ConfigureServices and use dependency injection to access the instance in your web request handlers.
i'm about to start writing a blog post on exactly this - look out for that (though there is some chance I'll change my mind on the topic, no guarantees until it's out!).
Thanks, sounds good. Looking forward to the blog, where would it be posted?
the confluent website
the confluent website
Is there a url now ?
sorry, haven't done it yet.
hi there. I am wondering if the Producer implementation is thread safe and the intention is to keep it thread safe. Also I haven't looked at the code, is it using HttpClient underneath because it may cause issue if we have a singleton HttpClient?
sorry, haven't done it yet.
馃槀 url now?
sorry, haven't done it yet.
How about now?
no blog post on this but there is a web example now: https://github.com/confluentinc/confluent-kafka-dotnet/tree/master/examples/Web