KafkaClient.NET 1.0.1

dotnet add package KafkaClient.NET --version 1.0.1
NuGet\Install-Package KafkaClient.NET -Version 1.0.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="KafkaClient.NET" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KafkaClient.NET --version 1.0.1
#r "nuget: KafkaClient.NET, 1.0.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.
// Install KafkaClient.NET as a Cake Addin
#addin nuget:?package=KafkaClient.NET&version=1.0.1

// Install KafkaClient.NET as a Cake Tool
#tool nuget:?package=KafkaClient.NET&version=1.0.1

Kafka Client library for .NET Core

Library Version: v1.0.0

Installation

Install-Package KafkaClient.NET

Usage

KafkaClient.NET is a simple library to Produce and Consume easily in .NET Core applications. It is a wrapper on official Confluent.Kafka client library. It supports simple objects and Protocolbuffer objects.

Setup DI

var serviceProvider = new ServiceCollection()
        .AddLogging(loggingBuilder =>
        {
            loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
        })
        .AddKafka(options =>
        {
            options.BootstrapServers = "10.1.1.1:9092"; // replace with yours
        })
                .BuildServiceProvider();
        .BuildServiceProvider();

Get Kafka Service instance

var kafka = serviceProvider.GetRequiredService<IKafkaService>();

Simple Producer Example

Create producer object

var p1 = kafka.CreateProducer<Null, string>(options =>
  {
      options.TopicName = "test-topic-01";
  });

Produce message

var dr = p1.ProduceAsync(new Message<Null, string> { Value = "test" }).Result;
Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");

Simple Consumer Example

Create consumer object

var c1 = kafka.CreateConsumer<Null, string>(options =>
  {
      options.TopicName = "test-topic-02";
      options.GroupId = "1";
      options.ThreadCount = 8;
  });

Start consuming

c1.StartConsumer(MessageReceived);

Stop consuming

c1.StopConsumer();

Producer Example with protobuf

Create producer object

var p2 = kafka.CreateProducerProtobuf<string, User>(options =>
  {
      options.TopicName = "test-topic-03";
      options.SchemaRegistryUrl = "10.1.1.1:8081"; // replace with yours
  });

Produce message

User user = new User { Name = "Imran Khan", FavoriteColor = "green", FavoriteNumber = 100 };
var dr = p2.ProduceAsync(new Message<string, User> { Key = user.Name, Value = user }).Result;
Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");

Consumer Example with protobuf

Create consumer object

var c2 = kafka.CreateConsumerProtobuf<string, User>(options =>
{
    options.TopicName = "test-topic-03";
    options.GroupId = "30";
    options.ThreadCount = 1;
    options.AutoOffsetReset = AutoOffsetReset.Earliest;
});

Start consuming

c2.StartConsumer(MessageReceived);

Stop consuming

c2.StopConsumer();

License

This library licensed under the MIT license.

Product 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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 1,063 12/13/2021
1.0.0 332 10/27/2021

added support for .net5.0