EasyCore.Kafka 8.3.1

dotnet add package EasyCore.Kafka --version 8.3.1
                    
NuGet\Install-Package EasyCore.Kafka -Version 8.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyCore.Kafka" Version="8.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyCore.Kafka" Version="8.3.1" />
                    
Directory.Packages.props
<PackageReference Include="EasyCore.Kafka" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyCore.Kafka --version 8.3.1
                    
#r "nuget: EasyCore.Kafka, 8.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EasyCore.Kafka@8.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyCore.Kafka&version=8.3.1
                    
Install as a Cake Addin
#tool nuget:?package=EasyCore.Kafka&version=8.3.1
                    
Install as a Cake Tool

πŸ“¨ EasyCore.Kafka

EasyCore.Kafka is a Kafka infrastructure client for .NET 8. Built on Confluent.Kafka, it provides DI registration, connect, topic publish/subscribe, and manual Commit. It is not tied to IEvent / EventBus β€” use it standalone, or via the EasyCore.EventBus.Kafka adapter.

.NET C# Kafka License Version


🌍 Language


πŸ“š Table of Contents


1. 🎯 Positioning

Scenario Fit?
Byte-level publish/subscribe on Kafka topics βœ…
Key, headers, and manual Commit βœ…
Unified IEvent + handler discovery (EDA) ❌ β†’ use EasyCore.EventBus.Kafka
In-process local events ❌ β†’ use EasyCore.EventBus local bus

1.1 Design Principles

Principle Meaning
Infrastructure layer Bootstrap, topics, consumer groups, and raw bytes
Standalone No dependency on the EasyCore.EventBus core package
Adapter-friendly The EventBus Kafka adapter reuses this client

2. Relation to EventBus

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  App code (any payload)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ IKafkaClient
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  EasyCore.Kafka (this)      β”‚  ← infrastructure client
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ Confluent.Kafka
               β–Ό
          Kafka Cluster

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EasyCore.EventBus.Kafka     β”‚  ← adapter: IEvent / Handler
β”‚   └── uses this client      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Package Role
EasyCore.Kafka Generic Kafka client (this package)
EasyCore.EventBus.Kafka Maps EventBus IEvent onto Kafka

3. βš™ Requirements

Item Requirement
.NET 8.0+
Dependency Confluent.Kafka 2.12.x (brought by this package)
Broker Reachable Kafka bootstrap servers

4. πŸ“₯ Installation

dotnet add package EasyCore.Kafka

5. ⚑ Quick Start

5️⃣.1️⃣ Register DI

using EasyCore.Kafka;

builder.Services.AddEasyCoreKafka(o =>
{
    o.BootstrapServers = "localhost:9092";
    o.TopicName = "EasyCore.Topic";
    o.GroupId = "EasyCore.GroupId";
    o.MessageTimeoutMs = 10000;
    o.RequestTimeoutMs = 10000;
});

5️⃣.2️⃣ Publish

public sealed class TelemetryPublisher
{
    private readonly IKafkaClient _client;

    public TelemetryPublisher(IKafkaClient client) => _client = client;

    public async Task PublishAsync(string deviceId, CancellationToken ct = default)
    {
        await _client.ConnectAsync(ct);

        var body = Encoding.UTF8.GetBytes($$"""{"deviceId":"{{deviceId}}"}""");
        var headers = new Dictionary<string, byte[]>
        {
            ["x-source"] = Encoding.UTF8.GetBytes("iot-gateway")
        };

        await _client.PublishAsync(
            topic: "telemetry.raw",
            body: body,
            key: deviceId,
            headers: headers,
            cancellationToken: ct);
    }
}

5️⃣.3️⃣ Subscribe and Commit

public sealed class TelemetryConsumer : BackgroundService
{
    private readonly IKafkaClient _client;

    public TelemetryConsumer(IKafkaClient client) => _client = client;

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        await _client.ConnectAsync(stoppingToken);

        await _client.SubscribeAsync(
            topics: new[] { "telemetry.raw" },
            handler: async (msg, ct) =>
            {
                var json = Encoding.UTF8.GetString(msg.Body.Span);
                // handle business…

                if (msg.NativeResult is not null)
                    _client.Commit(msg.NativeResult);

                await Task.CompletedTask;
            },
            cancellationToken: stoppingToken);
    }
}

KafkaDeliveredMessage fields: Topic, Key, Body, Headers, NativeResult (pass to Commit).


6. 🧩 API Overview

Member Description
AddEasyCoreKafka(Action<KafkaOptions>) DI: Options and IKafkaClient
ConnectAsync Initialize the consumer (idempotent)
PublishAsync(topic, body, key?, headers?) Produce to a topic
SubscribeAsync(topics, handler) Subscribe and start a background consume loop
Commit(nativeResult) Commit the offset for the delivered message

IKafkaClient implements IAsyncDisposable β€” dispose on shutdown.


7. Options (KafkaOptions)

Property Type Default Description
BootstrapServers string localhost:9092 Comma-separated bootstrap addresses
TopicName string EasyCore.Topic Topic name prefix (convention / adapter)
GroupId string EasyCore.GroupId Consumer group suffix
MessageTimeoutMs int 10000 Produce timeout (ms)
RequestTimeoutMs int 10000 Request timeout (ms)
QueueBufferingMaxMessages int 30000 Producer queue buffer size
AppName string? null Used in group naming; entry assembly when null

8. ❓ FAQ

Q: This package vs EasyCore.EventBus.Kafka?
A: Use the EventBus adapter for IEvent, handlers, and retries. Use this package for raw topic I/O.

Q: What do I pass to Commit?
A: Pass KafkaDeliveredMessage.NativeResult from the handler (the underlying consume result).

Q: What do TopicName / GroupId do when used standalone?
A: Naming conventions / suffixes. PublishAsync / SubscribeAsync still use the topics you pass in.

Q: Multiple bootstrap servers?
A: Yes β€” set BootstrapServers to e.g. kafka1:9092,kafka2:9092.


9. πŸ“„ License

MIT β€” see the repository LICENSE, or the NuGet package metadata.


🀝 Contributing

Issues and PRs are welcome. After changing this package, verify EasyCore.EventBus.Kafka and related demos.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EasyCore.Kafka:

Package Downloads
EasyCore.EventBus.Kafka

.NET Core EventBus distributed transport based on Kafka.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.3.1 118 8/4/2026
8.3.0 122 7/21/2026
8.0.0 127 7/18/2026