Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Program.CreateHostBuilder
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
// Add event processor
services.AddSingleton<IEventProcessor>(sp =>
{
// Create Kafka consumer and producer
var kafkaConsumer = KafkaUtils.CreateConsumer("localhost:9092", new List<string> { "raw-events" });
var kafkaProducer = KafkaUtils.CreateProducer("localhost:9092");
// Create handlers
var handlers = new List<MessageHandler> { new TransformHandler() };
// Create event processor
return new KafkaEventProcessor<int, string, int, string>(
new KafkaEventConsumer<int, string>(kafkaConsumer),
new KafkaEventProducer<int, string>(kafkaProducer, "processed-events"),
handlers.ToArray());
});
services.AddHostedService<Worker>();
});
}
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.