Event Driven Architecture :
Send command and Publish events.
Asynchronous messaging
A mechanism for Loosely coupled integration of software components. Publisher/subscriber pattern.
Advantage: Scalability, Reliability( Retry)
Service Bus – For Service Endpoint communication.
Allows services to communicate with each other, Have backend messaging implementation.
Service Bus Should not have any business logic, service should be smart enough.
- One endpoint connected to one queue
- One service can have multiple endpoint
Service Bus and Enterprise service Bus are different.
NServiceBus
Service Bus implementation in .NET – Open Source.
Not free. Licensing by Particular. Below link to find related documentation.
- Communication between application using messaging.
- Abstract on backend messaging.
- Support transport configuration like MSMQ, RabbitMQ, SQLServer
NugetPackages:
NServiceBus
NServiceBus.Host – Run as windows service.
NServiceBus.Testing
Commands:
Messages – In the form of C# Class have data in the form of properties.
Multiple senders
One Receiver
Send Method
Imperative – Create/Use
Heavily relies on DI – Lean version of Autofac Built into Core.
By assembly Scanning – Endpoints depend upon assemblies.
Events:
Messages
One Sender
Multiple Receivers
Publish/Subscriber pattern
Past tense : OrderProcessedEvent
Routing :
For Commands /Events
By 2 Ways -Config File or by Routing API(recommended)
IConfigureThisEndpoint
INeedInitialization
Serialization – Default Xml, Future will change to JSON
Persistence: No Default
NServiceBus Transport Options:
NService Bus provide abstract over transport. Easy to switch transport through configuration.
Messaging Middleware
- RabbitMQ
- MSMQ
- Kafka
- Azure Service Bus
MSMQ
- It does not support subscription.
- Native to windows
- Decentralize – Every Machine have own local queues.
RabbitMQ
- Broker style
- Centralize
- Exchange and Have a better routing mechanism.
MSQM Vs RabbitMQ – Microservice run on multiple OS. MSMQ limit to windows.
Azure – Storage queues Vs Service Bus(Costly, low latency).