ConfluentKafkaAspNetAdapter 0.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ConfluentKafkaAspNetAdapter --version 0.2.2
NuGet\Install-Package ConfluentKafkaAspNetAdapter -Version 0.2.2
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="ConfluentKafkaAspNetAdapter" Version="0.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConfluentKafkaAspNetAdapter --version 0.2.2
#r "nuget: ConfluentKafkaAspNetAdapter, 0.2.2"
#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 ConfluentKafkaAspNetAdapter as a Cake Addin
#addin nuget:?package=ConfluentKafkaAspNetAdapter&version=0.2.2

// Install ConfluentKafkaAspNetAdapter as a Cake Tool
#tool nuget:?package=ConfluentKafkaAspNetAdapter&version=0.2.2

Introduction

This library is used to more easily work with Confluents .NET client. It assumes that specific avro schemas are utilized.

Configuration

Necessary

The library is dependant on two configuration properties: MessageBroker:Uri and SchemaRegistry:Uri, they can either be set in the appsettings.json file or as Environmental Variables

Optional

The following values can be configured optionally:

Config Key Default Value
Consumer:AutoOffsetReset AutoOffsetReset.Earliest
SchemaRegistry:RequestTimeout 5000
SchemaRegistry:MaxCachedSchemas 10
MessageBroker:TopicNamespace

Exempels

To use this library, add the nuget package to the project that will use it. Within the ConfigureServices method in Startup.cs you are then able to use the extension methods AddKafkaReceiver and AddKafkaPublisher.

Syncronous Kafka Reciever

A syncronous kafka reciever is added to the DI IoC container as follows:

public void ConfigureServices(IServiceCollection services)
{
    services.AddKafkaReceiver<MessageType, KafkaUserMassageReciever>("Topic");
}

The KafkaMessageReciever-type must implement the IKafkaMessageReciever interface e.g:

public class KafkaUserMassageReciever : IKafkaMessageReciever<User>
{
    public void HandleMessage(User message)
    {
        Console.WriteLine(message);
    }
}

This creates a backround service that will create a Reciever of type KafkaUserMessageReciever everytime a message is added to that topic and the HandleMessagemethod will be called.

Asynchronous Kafka Reciever

An asyncronous kafka reciever enables awaiting calls within the HandleMessagemethod and is added to the DI IoC container as follows:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAsyncKafkaReceiver<MessageType, AsyncKafkaMessageReciever>("Topic");
}

The AsyncKafkaMessageReciever-type must implement the IAsyncKafkaMessageReciever interface e.g:

public class AsyncKafkaMessageReciever : IAsyncKafkaMessageReciever<User>
{
    public Task HandleMessage(User message)
    {
        Console.WriteLine(message);
        return Task.CompletedTask;
    }
}

Kafka publisher

A Kafka publisher is added to the DI IoC container as follows:

public void ConfigureServices(IServiceCollection services)
{
    services.AddKafkaPublisher<MessageType>("Topic");
}

The publisher can then be used inside a class as follows:

public class UserManipulator
{
    private readonly IKafkaMessagePublisher<User> kafkaMessagePublisher;
    private User user = new User();

    public UserManipulator(IKafkaMessagePublisher<User> kafkaMessagePublisher)
    {
        this.kafkaMessagePublisher = kafkaMessagePublisher;
    }

    public void AddName(string name)
    {
        user.Name = name;

        kafkaMessagePublisher.Publish(user);
    }
}

A message will then be published to the kafka buss on the specified topic

GroupId

GroupId can be specified for the recievers with the second parameter to the Add[Async]KafkaReciever method. If not specified the groupId is set to

$"{topic}-{Guid.NewGuid}-group"
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ConfluentKafkaAspNetAdapter:

Package Downloads
MachifuAuthentication

Package Description

ConfluentKafkaAspNetAdapterTestTools

This library is used to more easily test applications that has used the ConfluentKafkaAspNetAdapter.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-rc1 1,033 1/15/2020
0.4.1 2,717 9/10/2019
0.4.0 4,534 7/9/2019
0.4.0-rc 856 7/9/2019
0.3.1 1,106 7/5/2019
0.3.0 1,101 7/2/2019
0.2.3 1,154 6/5/2019
0.2.2 1,721 5/20/2019
0.2.1 1,328 5/14/2019
0.2.0 1,075 5/14/2019
0.2.0-beta 864 5/14/2019