Transports
Modulus supports three message broker transports: InMemory, RabbitMQ, and Azure Service Bus. You select a transport by setting the Transport enum on MessagingOptions. Your handler code remains identical regardless of which transport you choose -- only the configuration changes.
Transport Enum
public enum Transport
{
InMemory,
RabbitMq,
AzureServiceBus
}Configuration
builder.Services.AddModulusMessaging(options =>
{
options.Transport = Transport.InMemory;
options.Assemblies.Add(typeof(Program).Assembly);
// No ConnectionString required
});builder.Services.AddModulusMessaging(options =>
{
options.Transport = Transport.RabbitMq;
options.ConnectionString = "amqp://guest:guest@localhost:5672";
options.Assemblies.Add(typeof(Program).Assembly);
});builder.Services.AddModulusMessaging(options =>
{
options.Transport = Transport.AzureServiceBus;
options.ConnectionString = "Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-key";
options.Assemblies.Add(typeof(Program).Assembly);
});No handler changes required
Switching transports is a configuration-only change. Your IIntegrationEventHandler<T> implementations, IMessageBus calls, and event definitions remain exactly the same. This makes it straightforward to use InMemory for development and a real broker in production.
InMemory Transport
The InMemory transport runs entirely within the application process. Messages are delivered directly between publishers and consumers without any external broker.
When to use:
- Local development without requiring Docker or a broker installation
- Unit and integration testing
- Prototyping and rapid iteration
- Single-process deployments where cross-service communication is not needed
Characteristics:
- No external dependencies -- no broker to install or configure
- No
ConnectionStringrequired - Messages are not persisted -- if the process restarts, unprocessed messages are lost
- All delivery is in-process -- no network latency
builder.Services.AddModulusMessaging(options =>
{
options.Transport = Transport.InMemory;
options.Assemblies.Add(typeof(Program).Assembly);
});Not for production
The InMemory transport does not provide durable message delivery. Use it for development and testing only. For production workloads, use RabbitMQ or Azure Service Bus.
RabbitMQ Transport
The RabbitMQ transport connects to a RabbitMQ broker using the AMQP protocol. It provides durable queues, message acknowledgment, and exchange-based routing.
When to use:
- Self-hosted or on-premises environments
- Docker and Kubernetes deployments
- When you need fine-grained control over queues, exchanges, and routing
- Open-source and no per-message cost
Characteristics:
- Durable message delivery with acknowledgments
- Exchange and queue-based routing
- Dead-letter exchange support for failed messages
- MassTransit handles connection recovery automatically
Connection string format:
amqp://username:password@hostname:port/vhostExamples:
// Local development
options.ConnectionString = "amqp://guest:guest@localhost:5672";
// With virtual host
options.ConnectionString = "amqp://myuser:mypassword@rabbitmq.internal:5672/myapp";
// From configuration
options.ConnectionString = builder.Configuration.GetConnectionString("RabbitMq");Running RabbitMQ locally
The quickest way to run RabbitMQ locally is with Docker:
docker run -d --name rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:3-managementThe management UI is available at http://localhost:15672 (default credentials: guest / guest).
Azure Service Bus Transport
The Azure Service Bus transport connects to Azure Service Bus for fully managed, cloud-native messaging.
When to use:
- Azure-hosted workloads
- When you need a fully managed broker with no infrastructure to maintain
- Enterprise scenarios requiring advanced features (sessions, scheduled delivery, auto-forwarding)
- When SLA-backed message delivery is required
Characteristics:
- Fully managed -- no broker infrastructure to maintain
- Topics and subscriptions for pub/sub
- Queues for point-to-point messaging
- Built-in dead-letter queues
- SLA-backed availability
Connection string format:
Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-keyExamples:
// Direct connection string
options.ConnectionString = "Endpoint=sb://my-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123";
// From configuration
options.ConnectionString = builder.Configuration.GetConnectionString("AzureServiceBus");Environment-Based Transport Selection
A common pattern is to select the transport based on the environment:
builder.Services.AddModulusMessaging(options =>
{
if (builder.Environment.IsDevelopment())
{
options.Transport = Transport.InMemory;
}
else
{
options.Transport = Transport.RabbitMq;
options.ConnectionString = builder.Configuration
.GetConnectionString("RabbitMq")!;
}
options.Assemblies.Add(typeof(CatalogModule).Assembly);
options.Assemblies.Add(typeof(OrdersModule).Assembly);
});Configuration-driven transport
You can also read the transport from appsettings.json:
{
"Messaging": {
"Transport": "RabbitMq",
"ConnectionString": "amqp://guest:guest@localhost:5672"
}
}var messagingConfig = builder.Configuration.GetSection("Messaging");
builder.Services.AddModulusMessaging(options =>
{
options.Transport = Enum.Parse<Transport>(messagingConfig["Transport"]!);
options.ConnectionString = messagingConfig["ConnectionString"];
options.Assemblies.Add(typeof(Program).Assembly);
});Transport Comparison
| Feature | InMemory | RabbitMQ | Azure Service Bus |
|---|---|---|---|
| External broker | No | Yes (self-hosted) | Yes (managed) |
| Message durability | No | Yes | Yes |
| Dead-letter support | No | Yes | Yes |
| Network latency | None | Low (local) / Variable | Variable |
| Cost | Free | Free (open-source) | Pay-per-use |
| Best for | Dev / Test | Self-hosted / On-prem | Azure workloads |
| Connection string | Not required | amqp://... | Endpoint=sb://... |
See Also
- Overview -- Messaging setup and
MessagingOptionsreference - Message Bus -- The
IMessageBusAPI - Outbox Pattern -- Reliable publishing regardless of transport
- Inbox Pattern -- Idempotent consumption