Overview
The messaging infrastructure in AspNetRun Microservices enables asynchronous communication between services through event-driven architecture. It uses MassTransit as the abstraction layer over RabbitMQ for reliable message delivery.Architecture
The messaging system is built on:- BuildingBlocks.Messaging: Core messaging abstractions and events
- MassTransit: Message broker abstraction and routing
- RabbitMQ: Message broker for reliable message delivery
- Integration Events: Event definitions for cross-service communication
Key Components
Message Broker Configuration
TheAddMessageBroker extension method configures MassTransit with RabbitMQ:
Configuration Settings
Add these settings to yourappsettings.json:
Service Registration
Register the message broker in your service’sProgram.cs:
Assembly parameter automatically discovers and registers all IConsumer<T> implementations in your service.
Features
Endpoint Naming
MassTransit uses kebab-case endpoint naming convention automatically:BasketCheckoutEvent→basket-checkout-eventOrderCreatedEvent→order-created-event
Automatic Consumer Discovery
When you pass an assembly, MassTransit automatically:- Scans for classes implementing
IConsumer<TMessage> - Registers them in the DI container
- Creates queues and exchanges in RabbitMQ
- Routes messages to appropriate consumers
Reliable Delivery
RabbitMQ ensures:- Message persistence
- Automatic retries on failure
- Dead letter queues for failed messages
- Acknowledgments for processed messages
Message Flow
Next Steps
Events
Learn about the IntegrationEvent base class
Integration Events
Explore specific event implementations
