Bellight.MessageBus.Abstractions
10.0.3
dotnet add package Bellight.MessageBus.Abstractions --version 10.0.3
NuGet\Install-Package Bellight.MessageBus.Abstractions -Version 10.0.3
<PackageReference Include="Bellight.MessageBus.Abstractions" Version="10.0.3" />
<PackageVersion Include="Bellight.MessageBus.Abstractions" Version="10.0.3" />
<PackageReference Include="Bellight.MessageBus.Abstractions" />
paket add Bellight.MessageBus.Abstractions --version 10.0.3
#r "nuget: Bellight.MessageBus.Abstractions, 10.0.3"
#:package Bellight.MessageBus.Abstractions@10.0.3
#addin nuget:?package=Bellight.MessageBus.Abstractions&version=10.0.3
#tool nuget:?package=Bellight.MessageBus.Abstractions&version=10.0.3
Bellight.MessageBus.Abstractions
Provider-agnostic abstraction layer for message queuing and publish/subscribe messaging in .NET 10.
This package defines the contracts and the factory that application code programs against. It contains no transport logic. A concrete implementation package (e.g. Bellight.MessageBus.Amqp) must be registered at startup to handle the actual message delivery.
Concepts
Message bus types
MessageBusType |
Pattern | Delivery |
|---|---|---|
Queue |
Point-to-point | Exactly one consumer receives each message |
PubSub |
Publish/Subscribe | Every subscriber receives every message |
Core interfaces
| Interface | Role |
|---|---|
IMessageBusFactory |
Entry point — resolves publishers and subscriptions |
IPublisher |
Sends a string message to a named topic |
ISubscription |
Represents an active subscription; dispose to cancel |
IQueueProvider |
Implement this to provide a Queue transport |
IPubsubProvider |
Implement this to provide a PubSub transport |
Installation
dotnet add package Bellight.MessageBus.Abstractions
Registration
services.AddBellightMessageBus();
AddBellightMessageBus() registers IMessageBusFactory as a singleton and returns a MessageBusBuilder for chaining provider registrations.
Registering a provider package
Provider packages (e.g. Bellight.MessageBus.Amqp) extend MessageBusBuilder with their own fluent method:
services.AddBellightMessageBus()
.AddAmqp(opts => { opts.Endpoint = "amqp://localhost:5672"; });
Registering a custom provider directly
services.AddBellightMessageBus()
.AddQueueProvider<MyQueueProvider>()
.AddPubsubProvider<MyPubsubProvider>();
Usage
Inject IMessageBusFactory wherever you need to publish or subscribe.
Publishing
public class OrderService(IMessageBusFactory bus)
{
public async Task PlaceOrderAsync(string payload)
{
IPublisher publisher = bus.GetPublisher("orders", MessageBusType.Queue);
await publisher.SendAsync(payload);
}
}
GetPublisher is thread-safe and caches publisher instances by (topic, MessageBusType), so it is safe to call on every request.
Subscribing
public class OrderProcessor(IMessageBusFactory bus) : BackgroundService
{
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
ISubscription subscription = bus.Subscribe(
topic: "orders",
messageReceivedAction: async message =>
{
// handle message
await ProcessAsync(message);
},
messageBusType: MessageBusType.Queue);
stoppingToken.Register(() => subscription.Dispose());
return Task.CompletedTask;
}
}
Disposing the ISubscription cancels the consumer loop inside the transport implementation.
Implementing a custom provider
Implement IQueueProvider, IPubsubProvider, or both. Each interface inherits from IMessageBusProvider:
public interface IMessageBusProvider
{
IPublisher GetPublisher(string topic);
ISubscription Subscribe(string topic, Func<string, Task> messageReceivedAction);
}
Minimal skeleton:
public class InMemoryQueueProvider : IQueueProvider
{
public IPublisher GetPublisher(string topic)
=> new InMemoryPublisher(topic);
public ISubscription Subscribe(string topic, Func<string, Task> handler)
{
var cts = new CancellationTokenSource();
// start consumer loop, pass cts.Token
return new DefaultSubscription(cts);
}
}
DefaultSubscription is provided by this package. It wraps a CancellationTokenSource and cancels it on Dispose.
Provider resolution
MessageBusFactory resolves providers in this order:
- DI container — looks for a registered
IQueueProviderorIPubsubProvider. - Configuration fallback — if DI returns nothing, reads a type name from
IConfiguration:
| Bus type | Configuration key |
|---|---|
Queue |
Providers:MessageBusQueue |
PubSub |
Providers:MessageBusPubsub |
The configuration value must be an assembly-qualified type name:
{
"Providers": {
"MessageBusQueue": "My.Namespace.InMemoryQueueProvider, My.Assembly"
}
}
If neither source returns a provider, MessageBusProviderNotFoundException is thrown.
Exceptions
| Type | Thrown when |
|---|---|
MessageBusProviderNotFoundException |
No provider is found for the requested MessageBusType |
MessageBusException |
The resolved provider returns a null publisher |
Constants
Constants.DefaultPollingInterval // TimeSpan.FromSeconds(2)
Constants.DefaultWaitDuration // TimeSpan.FromSeconds(2)
Transport implementations should use these as their default polling and reconnect-wait values.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.8)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bellight.MessageBus.Abstractions:
| Package | Downloads |
|---|---|
|
Bellight.MessageBus.Amqp
AMQP implementation of Bellight.MessageBus.Abstractions using AMQPNetLite. Supports RabbitMQ and Azure Service Bus. Provides IQueueProvider and IPubsubProvider with polling-based message consumption and automatic link reconnection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.3 | 133 | 6/5/2026 |
| 10.0.1 | 139 | 5/8/2026 |
| 10.0.0 | 546 | 12/10/2025 |
| 9.0.2 | 243 | 7/28/2025 |
| 9.0.1 | 270 | 7/10/2025 |
| 9.0.0 | 272 | 12/6/2024 |
| 8.0.1 | 388 | 11/16/2023 |
| 7.0.0 | 626 | 11/11/2022 |
| 6.0.6 | 627 | 8/26/2022 |
| 6.0.5 | 580 | 8/26/2022 |
| 6.0.4 | 708 | 8/25/2022 |
| 6.0.3 | 713 | 8/19/2022 |
| 6.0.1 | 1,149 | 3/26/2022 |
| 6.0.0 | 744 | 3/25/2022 |
| 2.0.0 | 661 | 6/18/2021 |
| 1.0.2 | 8,312 | 12/19/2019 |
| 1.0.1 | 907 | 12/18/2019 |
| 1.0.0 | 966 | 8/29/2019 |