using System; using System.Text.Json; using System.Threading.Tasks; using Confluent.Kafka; using Serializers; using Model; class Producer { public static async Task Main (string[] args) { var config = new ProducerConfig { BootstrapServers = "localhost:29092" }; using (var producerBuilder = new ProducerBuilder(config) .SetValueSerializer(new JsonSerializer()) .Build()) { try { var msg = new Message { Key = System.Guid.NewGuid().ToString(), Value = new DataModel(System.Guid.NewGuid().ToString()) { name = "Name", description = "Description", notes = "This is a test object" } }; var dr = await producerBuilder.ProduceAsync("test-topic", msg); Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'"); } catch (ProduceException e) { Console.WriteLine($"Delivery failed: {e.Error.Reason}"); } } } }