Skip to content

Instantly share code, notes, and snippets.

@picadoh
Last active November 22, 2017 21:26
Show Gist options
  • Save picadoh/67ac767331030c194d262f678ee72848 to your computer and use it in GitHub Desktop.
Save picadoh/67ac767331030c194d262f678ee72848 to your computer and use it in GitHub Desktop.
Kafka Producer for .NET Core
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="0.11.2" />
</ItemGroup>
</Project>
namespace KafkaProducer
{
using System;
using System.Collections.Generic;
using System.Text;
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
public class Program
{
static void Main(string[] args)
{
var config = new Dictionary<string, object>
{
{ "bootstrap.servers", "localhost:9092" }
};
using (var producer = new Producer<Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
{
string text = null;
while (text != "exit")
{
text = Console.ReadLine();
producer.ProduceAsync("hello-topic", null, text);
}
producer.Flush(100);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment