Faster.Messagebus
0.0.8
dotnet add package Faster.Messagebus --version 0.0.8
NuGet\Install-Package Faster.Messagebus -Version 0.0.8
<PackageReference Include="Faster.Messagebus" Version="0.0.8" />
<PackageVersion Include="Faster.Messagebus" Version="0.0.8" />
<PackageReference Include="Faster.Messagebus" />
paket add Faster.Messagebus --version 0.0.8
#r "nuget: Faster.Messagebus, 0.0.8"
#:package Faster.Messagebus@0.0.8
#addin nuget:?package=Faster.Messagebus&version=0.0.8
#tool nuget:?package=Faster.Messagebus&version=0.0.8
🚀 Faster.MessageBus
Faster.MessageBus is a high-performance, decentralized message bus for .NET, built on NetMQ.
It enables services to form a self-organizing, self-healing peer-to-peer mesh network — with no central broker required.
⚠️ Note: This project is currently under active development and should be considered experimental.
The API may evolve before stable release.
✨ Key Features
- ⚡ Ultra-Fast Messaging — Zero-copy serialization and minimal allocations using
Span<T>andArrayPool<T>. - 🧩 Event & Command Dispatchers — Unified APIs for fire-and-forget events and request-reply commands.
- 🧭 Smart Routing Mechanism — Route messages locally, within a machine, across a cluster, or network-wide, even to specific applications.
- 🔁 Fluent Builder API — Configure timeouts, cancellation, and error handlers with clean, chainable syntax.
- 🔍 Automatic Discovery — Nodes automatically find each other and form a distributed mesh network.
- ❤️ Heartbeat Monitoring — Tracks node health and removes disconnected peers automatically.
- 🔒 Thread-Safe Core — Dedicated internal scheduler eliminates the need for locking in user code.
- 📦 Compact Serialization — Uses
MessagePack+LZ4for extremely fast and small payloads.
🧠 Core Architecture
Faster.MessageBus is a brokerless distributed messaging system for .NET.
Each application node acts as both publisher and subscriber, forming a mesh topology via NetMQ.
This allows:
- Event broadcasting (publish/subscribe)
- Command dispatching (request/reply)
- Scatter-gather communication
- Directed messaging to specific peers or groups
All of this happens without a central broker, giving you maximum speed, fault tolerance, and zero configuration overhead.
🧭 Intelligent Routing System
Faster.MessageBus introduces a 4-tier routing system, giving you full control over where and how messages travel.
| Scope | Description | Typical Use Case |
|---|---|---|
| 🧩 Local | Executes within the same process | In-memory testing or modular apps |
| 🖥️ Machine | Routes messages to all peers on the same host | Multi-process systems on a single server |
| 🌐 Cluster | Sends messages to all nodes within a logical service cluster | Microservice clusters, load-balanced systems |
| 🌍 Network | Broadcasts across all reachable nodes in the mesh | Cross-machine, cross-network event distribution |
Additionally, messages can target specific applications directly using:
.SendToAsync("app-name", command, timeout);
💬 Routing Examples
🔹 Local Command
await messageBus.CommandDispatcher.Local
.Prepare(new CacheRefreshCommand())
.WithTimeout(TimeSpan.FromSeconds(2))
.SendAsync();
🔹 Machine-Scoped Broadcast
await foreach (var response in messageBus.CommandDispatcher.Machine
.Prepare(new GetSystemStatusCommand())
.WithTimeout(TimeSpan.FromSeconds(3))
.StreamAsync())
{
Console.WriteLine($"Local service reported: {response.State}");
}
🔹 Cluster-Wide Scatter-Gather
await foreach (var result in messageBus.CommandDispatcher.Cluster
.Prepare(new SyncDatabaseCommand())
.WithTimeout(TimeSpan.FromSeconds(5))
.StreamResultAsync())
{
if (result.IsSuccess)
Console.WriteLine($"✔ Synced node: {result.Value.NodeName}");
else
Console.WriteLine($"⚠ Failed: {result.Error.Message}");
}
🔹 Directed Command (Targeted Application)
var response = await messageBus.CommandDispatcher.Network
.Prepare(new GetMetricsCommand())
.WithTimeout(TimeSpan.FromSeconds(2))
.SendToAsyncWithResult("pc2");
Console.WriteLine($"Metrics from pc2: {response.CpuUsage}%");
🔹 Event Broadcast
await messageBus.EventDispatcher.Publish(
new UserCreatedEvent(Guid.NewGuid(), "Alice"),
TimeSpan.FromSeconds(5),
CancellationToken.None
);
Handler:
public class UserCreatedEventHandler(ILogger<UserCreatedEventHandler> logger)
: IEventHandler<UserCreatedEvent>
{
public void Handle(UserCreatedEvent @event)
{
logger.LogInformation($"User created: {@event.UserName}");
}
}
🧱 Fluent Command Builder Overview
| Method | Description |
|---|---|
.WithTimeout(TimeSpan) |
Sets a per-command timeout |
.WithCancellation(CancellationToken) |
Attaches external cancellation logic |
.OnTimeout(Action<Exception, MeshContext>) |
Handles timeouts gracefully |
.SendAsync() |
Sends a one-way command |
.SendToAsync(string appId) |
Sends to a specific node |
.SendToAsyncWithResult(string appId) |
Sends to a specific node and awaits reply |
.StreamAsync() |
Streams multiple responses (scatter-gather) |
.StreamResultAsync() |
Streams Result<T> objects (with success/error info) |
Example:
await messageBus.CommandDispatcher.Cluster
.Prepare(new ReplicateCacheCommand())
.WithTimeout(TimeSpan.FromSeconds(4))
.OnTimeout((ex, ctx) => Console.WriteLine($"Timeout on {ctx.ApplicationId}: {ex.Message}"))
.SendAsync();
⚙️ Service Registration
services.AddEventHandlers();
services.AddCommandHandlers();
Automatically discovers and registers:
IEventHandler<T>ICommandHandler<T>ICommandHandler<T, TResult>
Works across .NET Framework, .NET Standard, .NET 8, and .NET 9.
🔍 SEO Keywords
.NET message bus • decentralized messaging • peer-to-peer message broker •
brokerless messaging system • distributed command routing • zero-broker architecture •
message queue alternative • high-performance messaging • event-driven .NET framework •
service mesh messaging • NetMQ command bus • publish/subscribe in .NET • scatter-gather commands
🤝 Contributing
Contributions are welcome! 🎉
Please open an issue first to discuss any proposed changes or enhancements.
📜 License
Licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- Faster.Transport (>= 0.0.18)
- MessagePack (>= 3.1.4)
- Microsoft.Extensions.Logging (>= 6.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.4)
- Microsoft.Extensions.Options (>= 6.0.1)
- NetMQ (>= 4.0.2.2)
-
.NETStandard 2.0
- Faster.Transport (>= 0.0.18)
- MessagePack (>= 3.1.4)
- Microsoft.Extensions.Logging (>= 6.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.4)
- Microsoft.Extensions.Options (>= 6.0.1)
- NetMQ (>= 4.0.2.2)
-
.NETStandard 2.1
- Faster.Transport (>= 0.0.18)
- MessagePack (>= 3.1.4)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Options (>= 9.0.10)
- NetMQ (>= 4.0.2.2)
-
net9.0
- Faster.Transport (>= 0.0.18)
- MessagePack (>= 3.1.4)
- Microsoft.Extensions.Logging (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Options (>= 9.0.10)
- NetMQ (>= 4.0.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.