Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using Confluent.Kafka;
namespace KafkaProducer
{
class Program
{
static void Main(string[] args)
{
var config = new ProducerConfig{ BootstrapServers = "kafka-release.kube-kafka.svc.cluster.local:9092" };
using (var producer = new ProducerBuilder<Null, string>(config).Build())
{
var increment = 0;
while (increment < int.MaxValue)
{
try
{
var produceResult = producer.ProduceAsync("increment-topic",
new Message<Null, string> { Value = $"The number is {increment}"})
.GetAwaiter()
.GetResult();
Console.WriteLine($"Success = {produceResult.Value} to {produceResult.TopicPartitionOffset}");
}
catch (Exception ex)
{
Console.WriteLine($"Error {ex.Message}");
}
increment++;
}
}
Console.WriteLine("Hello World!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment