Messaging Framework Overview
Messaging Framework Overview
Background
Real-world application should follow strong requirements for its
availability and scalability - such requirements would define distributed
nature of the application itself. Each part should be designed as self-
sufficient application then, but, putting all together, their should behave
as single one, at the end. Drawing analogy with human world - it's like a
sport team.
Requirements
The most natural communication approach - is asynchronous
messaging. There are a lot of solutions already done - either messaging
brokers or either orchestration frameworks.
1/13
Key requirements and responsibilities:
Messaging brokers:
RabbitMQ
Kafka
MSMQ
Azure Service Bus
Azure Events Hub
HTTP / REST
Messaging Framework uses latest .NET Core stack, supports all major OS
platforms (Linux, Mac OS and Windows) and fully compatible with .NET
Full Framework (version 4.6.1 or greater).
Market Solutions
Messaging Brokers
RabbitMQ + + -
Kafka + - -
MSMQ + + +
+ + -
Azure Service Bus
2/13
HTTP + - -
Messaging Patterns
Publisher-Subscriber + + +
Request-Response + + +
CQRS + + -
Saga + + -
Features
Single Interface - + -
Commercial License + - -
Easy Integratable - + -
Design
Contract
3/13
Message - represents a message and its metadata
MessagingBrokerFactory - represents factory that manages
messaging broker type factories
4/13
public static void RegisterBrokerFactory(string
schema, Func<string, IMessagingBroker> factory) { ...
}
}
Messaging Patterns
Publisher - Subscriber
This is the most basic and natural messaging pattern. It defines two
roles:
5/13
var eventsEntity = broker.GetEntity("core.events");
Shared Subscription
6/13
// First handler, whose predicate passes, will be
executed
Task<IMessagingSubscription>
SubscribeAsync(Func<Message, bool> filter,
Func<Message, Task> handler);
Typed Messaging
7/13
var jobProgressUpdateEvent = new
JobProgressUpdateEvent { JobId = 1, Progress = 0.11
};
await
eventsEntity.PublishAsync<JobProgressUpdateEvent>
(jobProgressUpdateEvent);
await
eventsEntity.SubscribeAsync<JobProgressUpdateEvent>
(jobProgressUpdateEvent =>
Task.CompletedTask // no-op handler
);
Competing Consumers
8/13
Request - Response
9/13
entity:
10/13
var jobsEntity = broker.GetEntity("core.jobs");
await
jobsEntity.RegisterHandlerAsync<CancelJobRequest,
CancelJobResponse>(cancelJobRequest =>
new CancelledJobResponse { JobId =
cancelJobRequest.JobId }
);
...
Extensibility
11/13
Service Provider
MSDN: https://docs.microsoft.com/en-us/dotnet/csharp/programming-
guide/classes-and-structs/extension-methods
broker.AddServiceFactory<IErrorHandlingStrategy>(_ =>
new CustomErrorHandlingStrategy());
12/13
CustomErrorHandlingStrategy();
broker.AddServiceFactory<IErrorHandlingStrategy>(_ =>
errorHandlingStartegy);
Custom Serialization
13/13