gsferreira.KafkaFlow.MediatR
3.0.0
dotnet add package gsferreira.KafkaFlow.MediatR --version 3.0.0
NuGet\Install-Package gsferreira.KafkaFlow.MediatR -Version 3.0.0
<PackageReference Include="gsferreira.KafkaFlow.MediatR" Version="3.0.0" />
paket add gsferreira.KafkaFlow.MediatR --version 3.0.0
#r "nuget: gsferreira.KafkaFlow.MediatR, 3.0.0"
// Install gsferreira.KafkaFlow.MediatR as a Cake Addin
#addin nuget:?package=gsferreira.KafkaFlow.MediatR&version=3.0.0
// Install gsferreira.KafkaFlow.MediatR as a Cake Tool
#tool nuget:?package=gsferreira.KafkaFlow.MediatR&version=3.0.0
KafkaFlow.MediatR
Introduction
An Extension to KafkaFlow that adds MediatR as a Middleware.
You can find samples here.
Installation
Using .NET CLI:
dotnet add package gsferreira.KafkaFlow.MediatR
Using NuGet:
Install-Package gsferreira.KafkaFlow.MediatR
Documentation
You can forward messages as Requests or Notifications to Mediator.
To do it, chain one of the middlewares provided by this library after a Serializer Middleware.
The serializer should be able to deserialize the incoming message into a message that implements MediatR IRequest
or INotification
.
Publishing Notifications
To publish messages as notifications to Mediator, use the middleware AddMediatorNotifications()
.
services.AddKafka(kafka =>
kafka
.AddCluster(cluster => cluster
.WithBrokers(new[] { "localhost:9092" })
.AddConsumer(consumer => consumer
.Topic("sample-topic")
.WithGroupId("sample-group")
.WithBufferSize(100)
.WithWorkersCount(10)
.AddMiddlewares(middlewares => middlewares
.AddSerializer<JsonCoreSerializer>()
.AddMediatorNotifications()
)
)
));
Publishing Requests
To publish messages as requests to Mediator, use the middleware AddMediatorRequests()
.
services.AddKafka(kafka =>
kafka
.AddCluster(cluster => cluster
.WithBrokers(new[] { "localhost:9092" })
.AddConsumer(consumer => consumer
.Topic("sample-topic")
.WithGroupId("sample-group")
.WithBufferSize(100)
.WithWorkersCount(10)
.AddMiddlewares(middlewares => middlewares
.AddSerializer<JsonCoreSerializer>()
.AddMediatorRequests()
)
)
));
Controlling lifetime
The default KafkaFlow Middleware lifetime isn't compatible with the default MediatR Handler lifetime.
You need to align those either through the Middleware overload AddMediatorNotifications(lifetime)
/AddMediatorNotifications(lifetime)
or through MediatR defaults configuration:
services.AddMediatR(cfg =>
{
cfg.Lifetime = ServiceLifetime.Singleton;
});
Get in touch
License
KafkaFlow.MediatR is a free and open source project, released under the permissible MIT license.
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 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. |
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 |
---|---|---|
3.0.0 | 492 | 12/5/2023 |
1.0.5-alpha.0.1 | 86 | 4/10/2023 |
1.0.4-alpha.0.2 | 73 | 4/10/2023 |
1.0.4-alpha.0.1 | 81 | 4/10/2023 |
1.0.3-alpha.0.4 | 57 | 12/5/2023 |
1.0.3-alpha.0.3 | 60 | 12/5/2023 |
1.0.3-alpha.0.2 | 61 | 12/5/2023 |
1.0.3-alpha.0.1 | 79 | 4/10/2023 |
1.0.2 | 394 | 4/6/2023 |
1.0.2-alpha.0.1 | 72 | 4/6/2023 |
1.0.0 | 201 | 3/29/2023 |
1.0.0-alpha.0.5 | 75 | 4/6/2023 |
1.0.0-alpha.0 | 76 | 4/6/2023 |