Program.CreateHostBuilder
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 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