Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created April 6, 2020 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/bbda28edf92af4368599c028261c9c25 to your computer and use it in GitHub Desktop.
Save xximjasonxx/bbda28edf92af4368599c028261c9c25 to your computer and use it in GitHub Desktop.
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