A lightweight, high-performance pub/sub messaging system for real-time communication between clients and servers. ExpressBus is engineered for low latency and high throughput using a partitioned concurrency model.
ExpressBus consists of two primary components:
- ExpressBus.Client: A client library for connecting to the broker, enabling subscription to topics and broadcasting of messages.
- ExpressBus.Server: A high-performance broker that coordinates topic subscriptions and distributes broadcast messages to subscribers.
using System.Net;
using System.Text;
using ExpressBus.Client;
// 1. Connect to the server
var endpoint = new IPEndPoint(IPAddress.Loopback, 8080);
var client = new ExpressBusClient(endpoint);
await client.ConnectAsync();
// 2. Subscribe to a topic
var topic = Encoding.UTF8.GetBytes("news");
await client.SubscribeAsync(topic, async message =>
{
Console.WriteLine($"Received: {Encoding.UTF8.GetString(message.Span)}");
});
// 3. Broadcast a message
await client.BroadcastAsync(topic, Encoding.UTF8.GetBytes("Hello, ExpressBus!"));using System.Net;
using ExpressBus.Server;
var address = new IPEndPoint(IPAddress.Any, 8080);
var server = new ExpressBusServer(address);
await server.ListenAsync();ExpressBus minimizes contention using Partitioned Locking. Rather than a single global lock for all subscriptions, it divides the subscription space into partitions, allowing concurrent operations across different topics.
TLS encryption is supported via the IStreamTransformer interface. This allows you to inject custom security layers (like SslStream) without modifying the core network logic.
The system uses ReadOnlyMemory<byte> throughout the pipeline to reduce allocations and avoid unnecessary copying of message payloads.
ExpressBus.Client— Client API and message dispatching.ExpressBus.Server— Pub/Sub broker implementation.ExpressBus.Protocol— Binary framing and serialization.ExpressBus.Network— TCP connection management and stream abstraction.ExpressBus.Concurrency— Specialized primitives for high-concurrency synchronization.ExpressBus.Equality— Optimized memory comparers for topic matching.
- Single-Node Broker: Designed for high throughput on a single machine. Horizontal scaling requires an external orchestrator.
- Ephemeral Messaging: Messages are broadcast in real-time; there is no built-in persistence or "message replay" for offline subscribers.