microservice.toolkit.messagemediator
0.9.1
See the version list below for details.
dotnet add package microservice.toolkit.messagemediator --version 0.9.1
NuGet\Install-Package microservice.toolkit.messagemediator -Version 0.9.1
<PackageReference Include="microservice.toolkit.messagemediator" Version="0.9.1" />
paket add microservice.toolkit.messagemediator --version 0.9.1
#r "nuget: microservice.toolkit.messagemediator, 0.9.1"
// Install microservice.toolkit.messagemediator as a Cake Addin #addin nuget:?package=microservice.toolkit.messagemediator&version=0.9.1 // Install microservice.toolkit.messagemediator as a Cake Tool #tool nuget:?package=microservice.toolkit.messagemediator&version=0.9.1
Message mediator
The library is a work in progress. It is not yet considered production-ready.
An interface to define how cloud microservices interact each other across multi instances, using request-response pattern.
How to install
Package Manager
Install-Package microservice.toolkit.messagemediator -Version 0.9.1
.NET CLI
dotnet add package microservice.toolkit.messagemediator --version 0.9.1
Package Reference
<PackageReference Include="microservice.toolkit.messagemediator" Version="0.9.1" />
Introduction
In Microservice Toolkit, a microservice has a name (or pattern) and returns with the following structure:
{
"error": 12,
"payload": {
...
}
}
Where:
- Error is the core of the error, it has value when an error occurs during service execution.
- Payload is the output of the service, it has value when the execution goes well.
Only one of the fields can have a value: if "error" has a value, "payload" doesn't have it, and vice versa.
Implementations
Microservice Toolkit provides some implementations of the message mediator interface:
The implementations of message mediator can work in a single instance environment
or in a multi instances environment:
A bus can be a message broker (RabbitMQ or Azure Service bus).
Every implementation requires a "service provider" (a delegate) to link the name (pattern) to the instance of a service.
Local
<a name="local"></a> To use in a single instance environment, in a desktop application, or to testing.
No external dependencies needed.
No external service will be query/use.
RabbitMQ
<a name="rabbitmq"></a> RabbitMQ is an open-source and lightweight message broker which supports multiple messaging protocols. It can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements. In addition, it's the most widely deployed message broker, used worldwide at small startups and large enterprises.
To start building RabbitMQ-based microservices, first install the required packages:
Install-Package RabbitMQ.Client -Version 6.2.2
Or:
<PackageReference Include="RabbitMQ.Client" Version="6.2.2" />
Azure Service Bus
<a name="servicebus"></a> To start building Azure Service Bus-based microservices, first install the required packages:
Install-Package Microsoft.Azure.ServiceBus -Version 5.1.3
Or:
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.1.3"/>
NATS
<a name="nats"></a> To start building NATS-based microservices, first install the required packages:
Install-Package NATS.Client -Version 1.0.2
Or:
<PackageReference Include="NATS.Clients" Version="1.0.2"/>
How to use
Service implementation
To implement a service, extend the abstract class "Service<TRequest, TPayload>", where:
- "TRequest" is the service input (or request)
- "TPayload" is the service output (or payload of the response)
Example code:
[Microservice("/user/exists")]
public class UserExists : Service<UserExistsRequest, UserExistsResponse>
{
public async override Task<ServiceResponse<UserExistsResponse>> Run(UserExistsRequest request)
{
return this.SuccessfulResponse(new UserExistsResponse
{
Exists = "Alice" == request.Username
});
}
}
Services registration
To register services, service factory and mediator into IoC (using Microsoft Dependency Injection), add to program startup ("services" is an instance of IServiceCollection):
using microservice.toolkit.messagemediator.extension;
[...]
// Registers all the microservices in the same assembly of "UserExists" class.
// Registers all the microservices as Singleton.
// Registers the service factory as Singleton.
var myAssembly = Assembly.GetAssembly(typeof(UserExists));
services.AddServiceContext(myAssembly);
[...]
// Registers message mediator
services.AddSingleton<IMessageMediator, LocalMessageMediator>();
Service call
To call a service using a mediator:
private readonly IMessageMediator mediator;
[...]
public MyClass(IMessageMediator mediator){
this.mediator = mediator;
}
[...]
// to explicit only payload type:
var response = await mediator.Send<int>(typeof(SquarePow), 2));
// or, to explicit request and payload type:
var response = await mediator.Send<int, int>(typeof(SquarePow), 2));
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. |
-
net6.0
- microservice.toolkit.core (>= 0.9.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on microservice.toolkit.messagemediator:
Package | Downloads |
---|---|
microservice.toolkit.entitystoremanager
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.1 | 118 | 7/30/2024 |
2.0.0 | 79 | 7/28/2024 |
1.1.1 | 138 | 7/19/2024 |
1.1.0 | 134 | 7/19/2024 |
1.0.0 | 136 | 6/10/2024 |
0.11.2 | 180 | 4/6/2024 |
0.11.1 | 189 | 3/30/2024 |
0.11.0 | 130 | 3/30/2024 |
0.10.2 | 306 | 3/15/2023 |
0.10.1 | 368 | 1/18/2023 |
0.10.0 | 347 | 1/11/2023 |
0.9.1 | 345 | 11/22/2022 |
0.9.0 | 385 | 11/16/2022 |
0.8.0 | 475 | 10/12/2022 |
0.7.0 | 470 | 4/28/2022 |
0.6.2 | 470 | 2/28/2022 |
0.6.1 | 479 | 2/21/2022 |
0.6.0 | 527 | 1/15/2022 |
0.5.0 | 359 | 12/8/2021 |
0.4.9 | 322 | 12/2/2021 |
0.4.8 | 296 | 12/2/2021 |
0.4.7 | 313 | 12/2/2021 |
0.4.6 | 321 | 12/1/2021 |
0.4.5 | 3,477 | 11/25/2021 |
0.4.4 | 375 | 11/2/2021 |
0.4.3 | 356 | 11/2/2021 |
0.4.2 | 382 | 10/27/2021 |
0.4.1 | 417 | 10/21/2021 |
0.4.0 | 526 | 10/3/2021 |