FonRadar.Base.EventBus.Kafka
1.0.7-beta
See the version list below for details.
dotnet add package FonRadar.Base.EventBus.Kafka --version 1.0.7-beta
NuGet\Install-Package FonRadar.Base.EventBus.Kafka -Version 1.0.7-beta
<PackageReference Include="FonRadar.Base.EventBus.Kafka" Version="1.0.7-beta" />
paket add FonRadar.Base.EventBus.Kafka --version 1.0.7-beta
#r "nuget: FonRadar.Base.EventBus.Kafka, 1.0.7-beta"
// Install FonRadar.Base.EventBus.Kafka as a Cake Addin
#addin nuget:?package=FonRadar.Base.EventBus.Kafka&version=1.0.7-beta&prerelease
// Install FonRadar.Base.EventBus.Kafka as a Cake Tool
#tool nuget:?package=FonRadar.Base.EventBus.Kafka&version=1.0.7-beta&prerelease
EventBus.Kafka
<b>EventBus.Kafka</b> is a <b>Kafka</b> implementation of the <a href="https://github.com/FonRadar/EventBus">Fon Radar Event Bus</a> <br> This nuget package provides a quick and clean solution to messaging with <b>Kafka</b> and currently supports only .NET 6 and .NET 7
Quick Start
To installing a package run command or install from nuget store.
dotnet add package FonRadar.Base.EventBus.Kafka
<br> Register your event bus like this
builder.Services
.AddEventBus()
.AddKafkaEventBus(myKafkaConfiguration =>
{
myKafkaConfiguration.Server = "myKafkaServer";
myKafkaConfiguration.Port = "myPort";
//And other fields you desire
});
or like this
builder.Services
.AddEventBus()
.AddKafkaEventBus("appsettings section goes here!");
An example appsettings section without authentication
{
"MyKafkaConfiguration": {
"Server": "localhost",
"Port": 9092,
"ConsumerGroupId": "kafka-consumers",
"IsUsingAuthentication" : false,
"Username": "these",
"Password": "values",
"SaslMechanism" : "are",
"SecurityProtocol" : "optional"
}
}
<br> An example appsettings section with authentication
{
"MyKafkaConfiguration": {
"Server": "localhost",
"Port": 9092,
"ConsumerGroupId": "kafka-consumers",
"IsUsingAuthentication" : true,
"Username": "admin",
"Password": "admin-secret",
"SaslMechanism" : "PLAIN",
"SecurityProtocol" : "Plaintext"
}
}
Note <br> Supported Sasl mechanisms values are GSSAPI, PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, OAUTHBEARER <br> Supported Security Protocol values are Plaintext, Ssl, SaslPlaintext, SaslSsl <br> These registration types are also supporting generic arguments <br> <br>
public interface INotificationServiceEventBus : IKafkaEventBus
{
}
<br>
public class NotificationServiceEventBus : KafkaEventBus, INotificationServiceEventBus
{
public NotificationServiceEventBus(ILogger<IEventBus> logger, ISubscriptionManager eventBusSubscriptionManager, IServiceScopeFactory serviceScopeFactory, KafkaServiceConfiguration kafkaServiceConfiguration)
: base(logger, eventBusSubscriptionManager, serviceScopeFactory, kafkaServiceConfiguration)
{
}
}
<br>
builder.Services
.AddEventBus()
.AddKafkaEventBus<INotificationServiceEventBus, NotificationServiceEventBus>("Integrations:NotificationService:Kafka");
<br> In order to messaging with <b>Kafka</b> objects should be inherited from <b>Event</b> class <br>
public record DummyEvent : Event
{
public string DummyMessage { get; set; }
}
Warning <br> <b>Curently Kafka topic names are created from class names, make sure producer and consumer have the same class name in both projects</b>
<br>
Producer
For producer, once event bus has registered, it can be simply published
private readonly IKafkaEventBus _eventBus; //This can be another implementation which inherits IKafkaEventBus
public EventPublisherProvider(
IKafkaEventBus eventBus
)
{
this._eventBus = eventBus;
}
public async Task PublishDummy(DummyEvent @event)
{
await this._eventBus.PublishAsync(@event);
}
Consumer
Consumer side must contain an event handler that inherits IEventHandler for every event
public class DummyEventHandler : IEventHandler<DummyEvent>
{
public Task HandleEvent(DummyEvent @event, CancellationToken cancellationToken)
{
//logic here
}
}
On service registration part event handlers must be registered
builder.Services.AddScoped<DummyEventHandler>();
Note Currently this registration step is manual, further improvements will focus on this situtation
<br> Consumer must subscribe every event that needs to processed
WebApplication app = builder.Build();
IKafkaEventBus eventBus = app.Services.GetRequiredService<IKafkaEventBus>();
eventBus.SubscribeAsync<DummyEvent, DummyEventHandler>(CancellationToken.None).ConfigureAwait(false);
<br>
Further improvements are on the way! 👨💻 <br> Feel free to share your thoughts or contribute to our project
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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. |
-
net6.0
- Confluent.Kafka (>= 1.9.2)
- FonRadar.Base.EventBus (>= 1.0.7-beta)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
-
net7.0
- Confluent.Kafka (>= 1.9.2)
- FonRadar.Base.EventBus (>= 1.0.7-beta)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
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.10-beta | 3,078 | 8/21/2023 |
1.0.9-beta | 264 | 7/12/2023 |
1.0.8-beta | 649 | 5/22/2023 |
1.0.7-beta | 223 | 3/22/2023 |
1.0.6-beta | 1,193 | 2/27/2023 |
1.0.5-beta | 129 | 2/24/2023 |
1.0.4-beta | 112 | 2/14/2023 |
1.0.3-beta | 101 | 2/14/2023 |
1.0.2-beta | 105 | 2/14/2023 |
1.0.1-beta | 106 | 2/14/2023 |
1.0.0-beta | 144 | 1/16/2023 |