-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
34 lines (30 loc) · 1.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Confluent.Kafka;
using KafkaParallelConsumer;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureLogging(c => c.AddSimpleConsole(o =>
{
o.SingleLine = true;
o.ColorBehavior = Microsoft.Extensions.Logging.Console.LoggerColorBehavior.Enabled;
o.IncludeScopes = true;
o.TimestampFormat = "hh:mm:ss:fff ";
}))
.ConfigureServices((hostContext, services) =>
{
var configuration = hostContext.Configuration.GetRequiredSection("Kafka:Consumer");
services.AddSingleton<ChannelProvider<string, string>>();
services.AddSingleton<KafkaPartitionsHandler<string, string>>();
services.AddSingleton(svc =>
{
var partitionsHandler = svc.GetRequiredService<KafkaPartitionsHandler<string, string>>();
var consumerConfig = configuration.GetRequiredSection("Client").Get<ConsumerConfig>();
return new ConsumerBuilder<string, string>(consumerConfig)
.SetPartitionsAssignedHandler(partitionsHandler.PartitionsAssignedHandler)
.SetPartitionsLostHandler(partitionsHandler.PartitionsLostHandler)
.Build();
});
services.AddSingleton<Processor<string, string>>();
services.AddHostedService<Worker<string, string>>()
.Configure<WorkerOptions>(configuration);
})
.Build();
await host.RunAsync();