Arbitrer provides MediatR Pipelines to transform mediator from In-process to Out-Of-Process messaging via RPC calls implemented with popular message dispatchers.
Mediatr is very good to implement some patterns like CQRS
Implementing CQRS in an in-process application does not bring to you all the power of the pattern but gives you the opportunity to have organized, easy to maintain code. When the application grow you may need to refactor your things to a microservices architecture.
Microservices and patterns like CQRS are very powerfull combination. In this scenario you will need to rewrite communication part to use some kind of out of process message dispatcher.
Arbitrer change Mediatr behaviour and let you decide which call needs to be in-process and which needs to be Out-of-process and dispatched remotely, via a configuration without changing a single row of your code.
Arbitrer follow MediatR versioning.
Arbitrer v.12.x is for MediatR from 12.x
Arbitrer v.9.0 is for MediatR from 9.x to 11.x
You should install Arbitrer with NuGet:
Install-Package Arbitrer
Or via the .NET Core command line interface:
dotnet add package Arbitrer
Either commands, from Package Manager Console or .NET Core CLI, will download and install Arbitrer and all required dependencies.
Configuring Arbitrer is an easy task.
- Add Arbitrer to services configuration via AddArbitrer extension method.
services.AddArbitrer(opt => ...
- Decide what is the default behaviour, available options are
- ImplicitLocal : all
mediator.Send()
calls will be delivered in-process unless further configuration. - ImplicitRemote : all
mediator.Send()
calls will be delivered out-of-process unless further configuration. - Explicit : you have the responsability do declare how to manage every single call.
- ImplicitLocal : all
services.AddArbitrer(opt =>
{
opt.Behaviour = ArbitrerBehaviourEnum.Explicit;
});
- Configure calls delivery type according with you behaviour:
services.AddArbitrer(opt =>
{
opt.Behaviour = ArbitrerBehaviourEnum.Explicit;
opt.SetAsRemoteRequest<MediatRRequest1>();
opt.SetAsRemoteRequest<MediatRRequest2>();
....
}
Of course you will have some processes with requests declared Local and other processes with same requests declared Remote.
services.AddArbitrer(opt =>
{
opt.Behaviour = ArbitrerBehaviourEnum.ImplicitLocal;
opt.SetAsRemoteRequest<MediatRRequest1>();
opt.SetAsRemoteRequest<MediatRRequest2>();
opt.SetAsRemoteRequests(typeof(MediatRRequest2).Assembly); // All requests in an assembly
});
services.AddArbitrer(opt =>
{
opt.Behaviour = ArbitrerBehaviourEnum.ImplicitLocal;
});
services.AddArbitrer(opt =>
{
opt.Behaviour = ArbitrerBehaviourEnum.ImplicitRemote;
});
Install-Package Arbitrer.RabbitMQ
Or via the .NET Core command line interface:
dotnet add package Arbitrer.RabbitMQ
Once installed you need to configure rabbitMQ extension.
services.AddArbitrerRabbitMQMessageDispatcher(opt =>
{
opt.HostName = "rabbit instance";
opt.Port = 5672;
opt.Password = "password";
opt.UserName = "rabbituser";
opt.VirtualHost = "/";
});
services.ResolveArbitrerCalls();
or if you prefer use appsettings configuration
services.AddArbitrerRabbitMQMessageDispatcher(opt => context.Configuration.GetSection("rabbitmq").Bind(opt));
services.ResolveArbitrerCalls();
Install-Package Arbitrer.Kafka
Or via the .NET Core command line interface:
dotnet add package Arbitrer.Kafka
Once installed you need to configure Kafka extension.
services.AddArbitrerKafkaMessageDispatcher(opt =>
{
opt.BootstrapServers = "localhost:9092";
});
services.ResolveArbitrerCalls();
or if you prefer use appsettings configuration
services.AddArbitrerKafkaMessageDispatcher(opt => context.Configuration.GetSection("kafka").Bind(opt));
services.ResolveArbitrerCalls();
Coming soon.