37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Confluent.Kafka;
|
|
using Model;
|
|
|
|
class Producer
|
|
{
|
|
public static async Task Main (string[] args)
|
|
{
|
|
var config = new ProducerConfig { BootstrapServers = "localhost:9092" };
|
|
|
|
using (var producerBuilder = new ProducerBuilder<string, DataModel>(config).Build())
|
|
{
|
|
try
|
|
{
|
|
var msg = new Message<string, DataModel>
|
|
{
|
|
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<string, DataModel> e)
|
|
{
|
|
Console.WriteLine($"Delivery failed: {e.Error.Reason}");
|
|
}
|
|
}
|
|
|
|
}
|
|
} |