Skip to content

Instantly share code, notes, and snippets.

@tonysneed
Last active June 25, 2020 22:38
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 tonysneed/9d234191ea38069ba09823206bbcf7e3 to your computer and use it in GitHub Desktop.
Save tonysneed/9d234191ea38069ba09823206bbcf7e3 to your computer and use it in GitHub Desktop.
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