Skip to content

Instantly share code, notes, and snippets.

@aramkoukia
Created March 26, 2018 03:44
Show Gist options
  • Save aramkoukia/d348a65d5e723d610133672d3ae31d1f to your computer and use it in GitHub Desktop.
Save aramkoukia/d348a65d5e723d610133672d3ae31d1f to your computer and use it in GitHub Desktop.
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
namespace kafka_prototype
{
class Program
{
static void Main(string[] args)
{
// The Kafka endpoint address
string kafkaEndpoint = "your_kafka_endpoint_from_cluster_dashboard";
// The Kafka topic we'll be using
string kafkaTopic = "testtopic";
// Create the producer configuration
var producerConfig = new Dictionary<string, object> { { "bootstrap.servers", kafkaEndpoint } };
// Create the producer
using (var producer = new Producer<Null, string>(producerConfig, null, new StringSerializer(Encoding.UTF8)))
{
// Send 10 messages to the topic
for (int i = 0; i < 10; i++)
{
var message = $"Event {i}";
var result = producer.ProduceAsync(kafkaTopic, null, message).GetAwaiter().GetResult();
Console.WriteLine($"Event {i} sent on Partition: {result.Partition} with Offset: {result.Offset}");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment