using Confluent.Kafka; namespace Cloud.Services { public class ProducerService { private readonly IProducer _producer; public ProducerService(IConfiguration configuration) { var producerConfig = new ProducerConfig { BootstrapServers = configuration["Kafka:BootstrapServers"] }; //Build the Producer _producer = new ProducerBuilder(producerConfig).Build(); } //Method for Produce the Message to Kafka Topic public async Task ProduceMessageAsync(string topic, string value) { var kafkaMessage = new Message { Key = Guid.NewGuid().ToString(), Value = value }; //Produce the Message await _producer.ProduceAsync(topic, kafkaMessage); } } }