Last active
November 22, 2017 21:26
-
-
Save picadoh/67ac767331030c194d262f678ee72848 to your computer and use it in GitHub Desktop.
Kafka Producer for .NET Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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