Closed Leela-SR closed 6 months ago
it doesn't extend easily. i think you'd need to create a new ProducerBuilder class that replicated all the existing methods + added your new handler. And this would return a different type of Producer, which wraps the existing one to intercept the produce calls and delivery results. You wouldn't necessarily have to keep the builder pattern - you could have a different style of api.
I have a similar use case @Leela-SR, and I'm solving it with KafkaFlow, which is built on top of Confluent's .NET Client and exposes that kind of functionality. https://farfetch.github.io/kafkaflow/docs/guides/middlewares/
I have resolved the Middleware problem using Chain of Responsibility Pattern. I add the Middleware (handlers) to LinkedList and execute the handlers on ProduceAsync call.
Description
ASP.Net core C#
I am trying to add the OpenTelemetry Kafka Instrumentation - Distributed Tracing to Producer. The Kafka Instrumentation is 100% working. I need to add this Instrumentation to Producer as a middleware or separate handler where I can easily hook or unhook this. I would like to whether we can add a middleware to the Producer. If yes, could any one provide the sample program.
Also, I am looking at the other option of extending the ProducerBuilder to add the handler - say TracingHandler.
How do I extend this and use the ProducerBuilder class?