Skip to content

Instantly share code, notes, and snippets.

@tonysneed

tonysneed/kafka-utils.cs

Last active Jun 25, 2020
Embed
What would you like to do?
Kafka Utility Methods
public static class KafkaUtils
{
public static IConsumer<int, string> CreateConsumer(string brokerList, List<string> topics)
{
var config = new ConsumerConfig
{
BootstrapServers = brokerList,
GroupId = "sample-consumer"
};
var consumer = new ConsumerBuilder<int, string>(config).Build();
consumer.Subscribe(topics);
return consumer;
}
public static IProducer<int, string> CreateProducer(string brokerList)
{
var config = new ProducerConfig { BootstrapServers = brokerList };
var producer = new ProducerBuilder<int, string>(config).Build();
return producer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.