OpenMessage aims to simplify the service bus paradigm by using pre-existing patterns to build an extensible architecture.
Designed for the generic hosting model that .Net Core 3 supports, the library aims to be able to cater for a wide range of scenarios, including receiving the same type from multiple sources - aiding a whole host of scenarios.
The core library OpenMessage
ships with an InMemory provider and a JSON serializer from the AspNetCore team (System.Text.Json
).
The library is based around the Microsoft.Extensions.*
packages and relies upon the abstractions for dependency injection and logging allowing you the freedom to pick the implementations that best suit your scenario.
Note: The rest of this guide requires you to be using version 3 of Microsoft.Extensions.*
.
1 - Install the OpenMessage
package:
PM> Install-Package OpenMessage
You may also any of the providers listed below for this sample as the Memory provider ships out of the box.
2 - Configure your host:
internal class Program
{
private static async Task Main()
{
await Host.CreateDefaultBuilder()
.ConfigureServices(services => services.AddOptions().AddLogging())
// Configure OpenMessage
.ConfigureMessaging(host =>
{
// Adds a memory based consumer and dispatcher
host.ConfigureMemory<Person>();
// Adds a handler that writes the entire message in json format to the console
host.ConfigureHandler<Person>(msg => Console.WriteLine($"Hello {msg.Value.Name}"));
})
.Build()
.RunAsync();
}
}
To send messages, inject IDispatcher<T>
and call DispatchAsync
and the library will route your message to the configured dispatcher for that type.
When a message is received, it flows as follows:
Message Pump > Channel > Consumer Pump > Pipeline > Handler
This library takes care of everything except the handlers. You have a few choices for implementing a handler, all registered via .ConfigureHandler
:
- Use a simple
Action<Message<T>>
- Use a simple
Func<Message<T>, Task>
- Inherit from
Handler<T>
- Implement
IHandler<T>
By default, after your handler has been run, and assuming the underlying provider supports it, the message is automatically acknowledged. This can be configured by calling ConfigurePipelineOptions<T>
as well as options for the consumer pump and handler timeout.
You can add more than one serializer to OpenMessage. In this scenario, all registered serializers are checked to see whether they can deserialize the message. When serializing the last registered serializer is used, service collection provider depending.
Here is a list of the available serializers:
- Hyperion
- Jil
- JsonDotNet
- MessagePack
- MsgPack
- Protobuf
- ServiceStackJson
- Utf8Json
- Wire
With OpenMessage you can easily receive from multiple sources in a centralised pipeline whilst providing as much of the underlying providers flexibility as possible.
Here is a list of the available providers:
- Apache Kafka
- AWS SQS
- AWS SNS
- AWS Kinesis
- AWS EventBridge
- Azure Event Hubs
- Azure Service Bus
- Eventstore
- InMemory
- MediatR
- NATS
- RabbitMq
Note: Any unchecked providers are currently a work in progress.