Bundle: redb-route / redb.Route.SignalR.StackExchangeRedis (redb.Route.SignalR.StackExchangeRedis.txt), 3 files Snapshot: development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt ==== Path: redb-route/redb.Route.SignalR.StackExchangeRedis/README.md Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.SignalR.StackExchangeRedis/README.md ---- # redb.Route.SignalR.StackExchangeRedis > Documentation and articles: Redis backplane for the [redb.Route SignalR transport](../redb.Route.SignalR/README.md). It scales hubs out across replicas, and it keeps the hubs of one listener apart on a shared Redis. [![NuGet](https://img.shields.io/nuget/v/redb.Route.SignalR.StackExchangeRedis?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.Route.SignalR.StackExchangeRedis) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../../LICENSE) | | | |---|---| | **NuGet** | `redb.Route.SignalR.StackExchangeRedis` | | **Dependencies** | `redb.Route.SignalR`, `Microsoft.AspNetCore.SignalR.StackExchangeRedis` (the ASP.NET Core line of the target framework: 8.0, 9.0 or 10.0) | | **Namespace** | `redb.Route.SignalR` | ## Why A SignalR hub keeps its connections and groups in the memory of one process. With two replicas behind a load balancer, a broadcast sent on one of them reaches only the clients attached to that one. A backplane carries every broadcast (`Clients.All`, `Group`, `User`) through Redis to the hub on every replica. SignalR names its Redis channels after the hub class. Every hub of the redb.Route transport is the same class, so a plain `AddStackExchangeRedis` gives `/orders` and `/alerts` the same channels, and their clients hear each other's broadcasts. This package keys the channels on the hub path, in code, for every hub. ## Installation ```bash dotnet add package redb.Route.SignalR.StackExchangeRedis ``` ## Usage With the SignalR registration of a host: ```csharp services.AddRedbRouteSignalR(o => o.UseRedisBackplane("redis:6379,password=...")); ``` With a component built by hand, as a Tsak module or a test does: ```csharp context.AddComponent(new SignalRComponent { ServerManager = shared, Authenticate = Validate } .UseRedisBackplane("redis:6379")); ``` The routes do not change: a hub (`From(SignalR.Hub("0.0.0.0:5090/hub/ui"))`) and its broadcast (`To(SignalR.Broadcast("0.0.0.0:5090/hub/ui").Method("uiChanged"))`) work as on a single replica, and a broadcast from any replica reaches the clients of `/hub/ui` on all of them. XML routes are the same URIs; the backplane is a setting of the component, not of a route. The second overload takes the Redis options alone, for a connection factory or a `ConfigurationOptions` built in code: ```csharp o.UseRedisBackplane(redis => redis.ConnectionFactory = async writer => await ConnectionMultiplexer.ConnectAsync(myConfigurationOptions, writer)); ``` ## Channel prefix | Configured `ChannelPrefix` | Hub path | Channels of the hub start with | |---|---|---| | none | `/hub/ui` | `/hub/ui` | | `myapp` | `/hub/ui` | `myapp/hub/ui` | The hub path is always part of the prefix. A prefix you set names the application or the stand, so several of them can share one Redis: ```csharp o.UseRedisBackplane("redis:6379", redis => redis.Configuration.ChannelPrefix = RedisChannel.Literal("shop-prod")); ``` The port is not part of the prefix: replicas behind a balancer may listen on different ports and still meet on the channels of their hub. ## One hub, one set of channels per process Within one process the same hub path on two ports is two different hubs. On one Redis without different prefixes they would publish on the same channels, so the second of them refuses to start: ```text SignalR hub /hub/ui on 0.0.0.0:5091 cannot use the Redis backplane channels '/hub/ui' on redis:6379: the hub /hub/ui on 0.0.0.0:5090 of this process already publishes on them ... Give the hubs different paths, or different ChannelPrefix values in UseRedisBackplane. ``` Give the hubs different paths, or give each its own `ChannelPrefix`. The check covers the hubs of the process that use this package with one copy of it loaded; on a Tsak worker that means the package is in the worker's shared layer, next to `redb.Route.SignalR`. ## Tsak cluster Every worker of a Tsak cluster is a replica: it runs the same packages, and the hub of each worker publishes on the same channels. The node id plays no part in the prefix, which is what lets the workers hear each other. Point the workers at one Redis, keep one `ChannelPrefix` per cluster (or none), and a broadcast from the worker that handled a message reaches the clients on every worker. ## A backplane added by hand `ConfigureHubServices` still accepts any backplane. Its delegate runs once per hub and gets the hub's description, so a hand-written Redis registration can key the channels the same way: ```csharp o.ConfigureHubServices((services, hub) => services.AddSignalR() .AddStackExchangeRedis("redis:6379", redis => redis.Configuration.ChannelPrefix = RedisChannel.Literal(hub.Path))); ``` Keeping the hubs apart is then the host's responsibility, and the one-hub-per-channels check above does not run. ## Limitations - Groups do not survive a reconnect, with or without a backplane: a reconnect is a new connection. See [Groups do not survive a reconnect](../redb.Route.SignalR/README.md#groups-do-not-survive-a-reconnect). - The backplane carries broadcasts, not connections: a client stays attached to the replica it negotiated with, so the balancer needs sticky sessions, unless every client skips negotiation and connects with WebSockets directly. - With a connection factory and no endpoints in the options, the one-hub-per-channels check treats every factory as the same Redis. Path: redb-route/redb.Route.SignalR.StackExchangeRedis/RedisBackplaneExtensions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.SignalR.StackExchangeRedis/RedisBackplaneExtensions.cs ---- using System.Net; using Microsoft.AspNetCore.SignalR.StackExchangeRedis; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using StackExchange.Redis; namespace redb.Route.SignalR; /// /// Redis backplane for the hubs of the SignalR transport. /// public static class RedisBackplaneExtensions { /// /// Scales every hub of the SignalR transport out through Redis: a broadcast (Clients.All, Group, /// User) sent on one replica reaches the clients of that hub on every replica. /// /// The Redis channels of a hub are keyed on its path. SignalR names them after the hub class, and every hub of the /// transport is the same class, so without that key two hubs on one Redis would see each other's broadcasts. A /// ChannelPrefix set in (the name of the application or the stand) comes first /// and the hub path follows it: myapp and /chat give myapp/chat. The hub path is always part /// of the prefix, so replicas of a hub meet on its channels whatever port each of them listens on. /// /// /// A hub refuses to start when another hub of this process already holds its channels on the same Redis: the same /// path on two ports with the same prefix. Give the hubs different paths or different prefixes. /// /// /// The SignalR registration options. /// Redis connection string (redis:6379,password=...). /// Further Redis options: a ChannelPrefix of the application, a connection factory. public static SignalRRegistrationOptions UseRedisBackplane(this SignalRRegistrationOptions options, string configuration, Action? configure = null) { ArgumentNullException.ThrowIfNull(options); ArgumentException.ThrowIfNullOrWhiteSpace(configuration); return options.ConfigureHubServices(Backplane(configuration, configure)); } /// /// Scales every hub of the SignalR transport out through Redis, with the connection described by /// alone (Configuration or ConnectionFactory). The channels are keyed on /// the hub path as in . /// /// The SignalR registration options. /// The Redis options. public static SignalRRegistrationOptions UseRedisBackplane(this SignalRRegistrationOptions options, Action configure) { ArgumentNullException.ThrowIfNull(options); ArgumentNullException.ThrowIfNull(configure); return options.ConfigureHubServices(Backplane(null, configure)); } /// /// The same backplane for a component built by hand (new SignalRComponent { ... }, as a Tsak module does): /// it is added to the component's , after what is there. /// See . /// /// The SignalR component. /// Redis connection string (redis:6379,password=...). /// Further Redis options: a ChannelPrefix of the application, a connection factory. public static SignalRComponent UseRedisBackplane(this SignalRComponent component, string configuration, Action? configure = null) { ArgumentNullException.ThrowIfNull(component); ArgumentException.ThrowIfNullOrWhiteSpace(configuration); return AddTo(component, Backplane(configuration, configure)); } /// /// The backplane of for a component /// built by hand. /// /// The SignalR component. /// The Redis options. public static SignalRComponent UseRedisBackplane(this SignalRComponent component, Action configure) { ArgumentNullException.ThrowIfNull(component); ArgumentNullException.ThrowIfNull(configure); return AddTo(component, Backplane(null, configure)); } private static SignalRComponent AddTo(SignalRComponent component, Action backplane) { var previous = component.HubServicesConfigurator; component.HubServicesConfigurator = previous is null ? backplane : (services, hub) => { previous(services, hub); backplane(services, hub); }; return component; } private static Action Backplane(string? configuration, Action? configure) => (services, hub) => { var signalR = services.AddSignalR(); if (configuration is not null) signalR.AddStackExchangeRedis(configuration, redis => configure?.Invoke(redis)); else signalR.AddStackExchangeRedis(configure!); // After every Configure, so the prefix of the application is known and the hub path is added to it. services.PostConfigure(redis => redis.Configuration.ChannelPrefix = RedisBackplaneChannels.Prefix(redis.Configuration.ChannelPrefix, hub.Path)); services.AddSingleton(sp => new RedisBackplaneClaim(hub, sp.GetRequiredService>().Value, sp.GetService() ?? RedisBackplaneClaims.Process)); }; } /// The channel prefix of a hub on the Redis backplane. internal static class RedisBackplaneChannels { /// The prefix of the application, if any, followed by the hub path. public static RedisChannel Prefix(RedisChannel application, string hubPath) => RedisChannel.Literal(application.IsNullOrEmpty ? hubPath : application.ToString() + hubPath); /// The Redis a backplane publishes to: its endpoints, in a stable order. public static string Server(RedisOptions redis) => string.Join(",", redis.Configuration.EndPoints.Select(Format).Order(StringComparer.OrdinalIgnoreCase)); private static string Format(EndPoint endpoint) => endpoint switch { DnsEndPoint dns => $"{dns.Host}:{dns.Port}", _ => endpoint.ToString() ?? "", }; } /// /// The channels the hubs of one process hold on their Redis servers. A process has one; a test that plays several /// replicas in one process gives each hub container its own. /// internal sealed class RedisBackplaneClaims { /// The claims of this process. public static RedisBackplaneClaims Process { get; } = new(); private readonly Dictionary _holders = new(StringComparer.Ordinal); /// Claims for ; the hub that already holds it, if any. public SignalRHubDescriptor? TryClaim(string key, SignalRHubDescriptor hub) { lock (_holders) { if (_holders.TryGetValue(key, out var holder)) return holder; _holders[key] = hub; return null; } } /// Releases when holds it. public void Release(string key, SignalRHubDescriptor hub) { lock (_holders) { if (_holders.TryGetValue(key, out var holder) && ReferenceEquals(holder, hub)) _holders.Remove(key); } } } /// /// Holds the channels of one hub on one Redis for as long as the hub runs, and refuses a second hub of this process /// that would publish on the same ones: the two would see each other's broadcasts. Started and stopped with the hub /// as a hosted service of its container. /// internal sealed class RedisBackplaneClaim(SignalRHubDescriptor hub, RedisOptions redis, RedisBackplaneClaims claims) : IHostedService { private readonly string _key = RedisBackplaneChannels.Server(redis) + "|" + redis.Configuration.ChannelPrefix; public Task StartAsync(CancellationToken cancellationToken) { if (claims.TryClaim(_key, hub) is { } holder) throw new InvalidOperationException( $"SignalR hub {hub.Path} on {hub.Host}:{hub.Port} cannot use the Redis backplane channels " + $"'{redis.Configuration.ChannelPrefix}' on {Describe(redis)}: the hub {holder.Path} on " + $"{holder.Host}:{holder.Port} of this process already publishes on them, and the two hubs would " + "see each other's broadcasts. Give the hubs different paths, or different ChannelPrefix values " + "in UseRedisBackplane."); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) { claims.Release(_key, hub); return Task.CompletedTask; } private static string Describe(RedisOptions redis) => RedisBackplaneChannels.Server(redis) is { Length: > 0 } server ? server : "the Redis of the connection factory"; } Path: redb-route/redb.Route.SignalR.StackExchangeRedis/redb.Route.SignalR.StackExchangeRedis.csproj Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.SignalR.StackExchangeRedis/redb.Route.SignalR.StackExchangeRedis.csproj ---- redb.Route.SignalR.StackExchangeRedis Redis backplane for the redb.Route SignalR transport. Scales hubs out across replicas and keys the Redis channels on the hub path, so the hubs of one listener never see each other's broadcasts on a shared Redis. esb;messaging;signalr;redis;backplane;scale-out;redb README.md