Kafka Utility Methods
This file contains 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
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