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.Message Contract
All messages must implement theIMessage interface:
Message Implementation
Message Envelope
Internally, SimpleMessageBus wraps your messages in aMessageEnvelope 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
SimpleMessageBus provides two built-in dispatcher implementations:Parallel Dispatcher
Processes messages concurrently for maximum throughput:Ordered Dispatcher
Processes messages sequentially to maintain order: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
Each provider implements its own queue processor:- Azure Storage Queue Processor: Polls Azure Storage Queues
- Amazon SQS Processor: Long-polls Amazon SQS queues
- File System Processor: Watches file system directories
- IndexedDB Processor: Monitors IndexedDB for new messages
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