Architecture Overview
SimpleMessageBus follows a publisher-subscriber pattern with the following key components:
- Messages: Data structures that carry information between components
- Publishers: Components that send messages to a transport mechanism
- Handlers: Components that process messages when they are received
- Dispatchers: Components that coordinate message delivery to handlers
- Providers: Transport-specific implementations (Azure, AWS, File System, IndexedDB)
Messages
Messages are the fundamental units of communication in SimpleMessageBus. They represent events, commands, or notifications that need to be processed.1
Define the Message Contract
All messages must implement the
IMessage interface:2
Implement Your Message
Create a message class with the data you need to communicate:
3
Understand the Message Envelope
Internally, SimpleMessageBus wraps your messages in a
MessageEnvelope that adds metadata:Publishers
Publishers are responsible for sending messages to the underlying transport mechanism. They serialize messages and handle transport-specific details.IMessagePublisher Interface
Usage Example
Handlers
Handlers contain the business logic for processing messages. They implement theIMessageHandler<T> interface.
IMessageHandler Interface
Handler Implementation
Dispatchers
Dispatchers coordinate the delivery of messages from the transport mechanism to the appropriate handlers. They handle deserialization, routing, and error handling.IMessageDispatcher Interface
Dispatcher Types
Parallel Dispatcher
Parallel Dispatcher
Processes messages concurrently for maximum throughput:Best for: High-throughput scenarios where message order doesn’t matter.
Ordered Dispatcher
Ordered Dispatcher
Processes messages sequentially to maintain order:Best for: Scenarios where processing order must be maintained.
Queue Processors
Queue processors are provider-specific components that poll the underlying transport for new messages and forward them to dispatchers.IQueueProcessor Interface
Provider-Specific Processors
Azure Storage Queue Processor
Azure Storage Queue Processor
Polls Azure Storage Queues for new messages using configurable polling intervals.Features:
- Configurable polling intervals
- Automatic message visibility timeout handling
- Batch message retrieval
Amazon SQS Processor
Amazon SQS Processor
Long-polls Amazon SQS queues for efficient message retrieval.Features:
- Long polling support (up to 20 seconds)
- FIFO queue support
- Dead letter queue integration
File System Processor
File System Processor
Watches file system directories for new message files.Features:
- FileSystemWatcher integration
- Automatic file cleanup
- Error file handling
IndexedDB Processor
IndexedDB Processor
Monitors IndexedDB for new messages in Blazor WebAssembly applications.Features:
- Browser-native storage
- Offline-first support
- Client-side message processing
Message Flow
Here’s how messages flow through the system:- Application creates and publishes a message
- Publisher serializes and sends the message to the transport
- Transport stores the message (queue, file, database)
- Queue Processor retrieves the message from transport
- Dispatcher deserializes and routes the message
- Handler processes the message with business logic
Error Handling
SimpleMessageBus provides several mechanisms for handling errors:Retry Mechanisms
Retry Mechanisms
Most providers support automatic retry with configurable policies:Configure exponential backoff to handle transient failures gracefully.
Dead Letter Queues
Dead Letter Queues
Failed messages can be automatically moved to dead letter queues:Isolate poison messages for later analysis and manual intervention.
Exception Handling
Exception Handling
Handlers should implement proper exception handling:Distinguish between retriable transient failures and permanent business logic errors.