gsferreira.KafkaFlow.MediatR
1.0.4-alpha.0.1
See the version list below for details.
dotnet add package gsferreira.KafkaFlow.MediatR --version 1.0.4-alpha.0.1
NuGet\Install-Package gsferreira.KafkaFlow.MediatR -Version 1.0.4-alpha.0.1
<PackageReference Include="gsferreira.KafkaFlow.MediatR" Version="1.0.4-alpha.0.1" />
paket add gsferreira.KafkaFlow.MediatR --version 1.0.4-alpha.0.1
#r "nuget: gsferreira.KafkaFlow.MediatR, 1.0.4-alpha.0.1"
// Install gsferreira.KafkaFlow.MediatR as a Cake Addin #addin nuget:?package=gsferreira.KafkaFlow.MediatR&version=1.0.4-alpha.0.1&prerelease // Install gsferreira.KafkaFlow.MediatR as a Cake Tool #tool nuget:?package=gsferreira.KafkaFlow.MediatR&version=1.0.4-alpha.0.1&prerelease
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 | 3,384 | 12/5/2023 |
1.0.5-alpha.0.1 | 92 | 4/10/2023 |
1.0.4-alpha.0.2 | 79 | 4/10/2023 |
1.0.4-alpha.0.1 | 89 | 4/10/2023 |
1.0.3-alpha.0.4 | 62 | 12/5/2023 |
1.0.3-alpha.0.3 | 64 | 12/5/2023 |
1.0.3-alpha.0.2 | 66 | 12/5/2023 |
1.0.3-alpha.0.1 | 85 | 4/10/2023 |
1.0.2 | 532 | 4/6/2023 |
1.0.2-alpha.0.1 | 80 | 4/6/2023 |
1.0.0 | 222 | 3/29/2023 |
1.0.0-alpha.0.5 | 82 | 4/6/2023 |
1.0.0-alpha.0 | 83 | 4/6/2023 |