microservice.toolkit.messagemediator
0.10.2
See the version list below for details.
dotnet add package microservice.toolkit.messagemediator --version 0.10.2
NuGet\Install-Package microservice.toolkit.messagemediator -Version 0.10.2
<PackageReference Include="microservice.toolkit.messagemediator" Version="0.10.2" />
paket add microservice.toolkit.messagemediator --version 0.10.2
#r "nuget: microservice.toolkit.messagemediator, 0.10.2"
// Install microservice.toolkit.messagemediator as a Cake Addin #addin nuget:?package=microservice.toolkit.messagemediator&version=0.10.2 // Install microservice.toolkit.messagemediator as a Cake Tool #tool nuget:?package=microservice.toolkit.messagemediator&version=0.10.2
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.10.2
.NET CLI
dotnet add package microservice.toolkit.messagemediator --version 0.10.2
Package Reference
<PackageReference Include="microservice.toolkit.messagemediator" Version="0.10.2" />
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 message mediator (IMessageMediator) implementations which can exchange messages in a single instance environment and in a multi instances environment using a message broker like RabbitMQ, Azure Service Bus or NATS.
Single instance environment:
Multi instances environment:
Every implementation of message mediator requires a "service factory" which link service name (pattern) to its instance.
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 response payload)
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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- microservice.toolkit.core (>= 0.10.2)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
-
net7.0
- microservice.toolkit.core (>= 0.10.2)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.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 | 121 | 7/30/2024 |
2.0.0 | 82 | 7/28/2024 |
1.1.1 | 141 | 7/19/2024 |
1.1.0 | 137 | 7/19/2024 |
1.0.0 | 139 | 6/10/2024 |
0.11.2 | 182 | 4/6/2024 |
0.11.1 | 191 | 3/30/2024 |
0.11.0 | 132 | 3/30/2024 |
0.10.2 | 308 | 3/15/2023 |
0.10.1 | 370 | 1/18/2023 |
0.10.0 | 349 | 1/11/2023 |
0.9.1 | 347 | 11/22/2022 |
0.9.0 | 387 | 11/16/2022 |
0.8.0 | 477 | 10/12/2022 |
0.7.0 | 472 | 4/28/2022 |
0.6.2 | 472 | 2/28/2022 |
0.6.1 | 481 | 2/21/2022 |
0.6.0 | 529 | 1/15/2022 |
0.5.0 | 361 | 12/8/2021 |
0.4.9 | 324 | 12/2/2021 |
0.4.8 | 298 | 12/2/2021 |
0.4.7 | 315 | 12/2/2021 |
0.4.6 | 323 | 12/1/2021 |
0.4.5 | 3,479 | 11/25/2021 |
0.4.4 | 377 | 11/2/2021 |
0.4.3 | 358 | 11/2/2021 |
0.4.2 | 386 | 10/27/2021 |
0.4.1 | 419 | 10/21/2021 |
0.4.0 | 528 | 10/3/2021 |