Confluent.Kafka.DependencyInjection
2.0.0
See the version list below for details.
dotnet add package Confluent.Kafka.DependencyInjection --version 2.0.0
NuGet\Install-Package Confluent.Kafka.DependencyInjection -Version 2.0.0
<PackageReference Include="Confluent.Kafka.DependencyInjection" Version="2.0.0" />
<PackageVersion Include="Confluent.Kafka.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Confluent.Kafka.DependencyInjection" />
paket add Confluent.Kafka.DependencyInjection --version 2.0.0
#r "nuget: Confluent.Kafka.DependencyInjection, 2.0.0"
#:package Confluent.Kafka.DependencyInjection@2.0.0
#addin nuget:?package=Confluent.Kafka.DependencyInjection&version=2.0.0
#tool nuget:?package=Confluent.Kafka.DependencyInjection&version=2.0.0
Kafka Dependency Injection
An extension of Confluent's Kafka client for use with Microsoft.Extensions.DependencyInjection (and friends).
Features
- Configure Kafka producers/consumers using
Microsoft.Extensions.DependencyInjection.IServiceCollection. - Default logging of asynchronous Kafka events through
Microsoft.Extensions.Logging.ILogger.
Installation
Add the NuGet package to your project:
$ dotnet add package Confluent.Kafka.DependencyInjection
Usage
Add a global Kafka client:
services.AddKafkaClient(new Dictionary<string, string>
{
{ "bootstrap.servers", "localhost:9092" },
{ "enable.idempotence", "true" },
{ "group.id", "group1" }
});
Alternatively, add typed clients with distinct configurations:
services.AddKafkaClient<MyService>(new ProducerConfig
{
BootstrapServers = "localhost:9092",
EnableIdempotence = true
});
services.AddKafkaClient<MyOtherService>(new ConsumerConfig
{
BootstrapServers = "somewhere.else:9092",
GroupId = "group1"
});
Optionally, configure message serialization:
// Use open generics to apply to all keys and values.
services.AddSingleton(typeof(IAsyncDeserializer<>), typeof(AvroDeserializer<>));
// Use closed generics to select type-specific serializers.
services.AddSingleton<IAsyncSerializer<MyType>, JsonSerializer<MyType>>();
// Synchronous serializers take precedence, if present.
services.AddSingleton(sp => sp.GetRequiredService<IAsyncSerializer<MyType>>().AsSyncOverAsync());
// Configure schema registry (required by some serializers).
services.AddSingleton<ISchemaRegistryClient>(sp =>
new CachedSchemaRegistryClient(new SchemaRegistryConfig
{
Url = "localhost:8081"
}));
Optionally, configure custom handlers for Kafka events:
services.AddTransient<IErrorHandler, MyHandler>()
.AddTransient<IStatisticsHandler, MyHandler>()
.AddTransient<ILogHandler, MyHandler>()
.AddTransient<IPartitionsAssignedHandler, MyHandler>()
.AddTransient<IPartitionsRevokedHandler, MyHandler>()
.AddTransient<IOffsetsCommittedHandler, MyHandler>();
Inject producers/consumers via constructor:
public MyService(IProducer<Null, string> producer)
{
// Producer is a singleton managed by the container.
this.producer = producer;
}
Alternatively, inject IKafkaFactory to override configuration and control lifespan:
using var consumer = factory.CreateConsumer<MyType, MyOtherType>(new ConsumerConfig
{
GroupId = "group2"
});
// ...
// Remember to close manually created consumers.
consumer.Close();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Confluent.Kafka (>= 1.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
-
net5.0
- Confluent.Kafka (>= 1.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Confluent.Kafka.DependencyInjection:
| Package | Downloads |
|---|---|
|
DanielXOO.Serilog.Sinks.Kafka
Serilog sink for kafka |
|
|
SkillAssessor.Common.Logging
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0 | 1,170 | 12/10/2025 |
| 3.4.0 | 46,486 | 7/19/2025 |
| 3.3.0 | 21,620 | 6/20/2025 |
| 3.2.0 | 47,192 | 3/15/2025 |
| 3.1.0 | 303,279 | 7/21/2023 |
| 3.0.2 | 344 | 7/21/2023 |
| 3.0.1 | 15,736 | 4/16/2023 |
| 3.0.0 | 61,342 | 3/28/2023 |
| 3.0.0-test3 | 315 | 3/27/2023 |
| 3.0.0-test2 | 746 | 3/21/2023 |
| 3.0.0-test | 294 | 3/10/2023 |
| 2.2.0 | 17,777 | 2/17/2023 |
| 2.1.2 | 14,786 | 2/2/2023 |
| 2.1.1 | 22,959 | 1/3/2023 |
| 2.1.0 | 34,364 | 11/3/2022 |
| 2.0.1 | 3,738 | 11/2/2022 |
| 2.0.1-test | 313 | 11/2/2022 |
| 2.0.0 | 130,662 | 6/21/2021 |
| 1.1.0 | 7,525 | 2/28/2021 |
| 1.0.0 | 934 | 1/8/2021 |
| 0.1.0 | 1,107 | 6/15/2020 |