Fluens.Messaging.Redis 0.9.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Fluens.Messaging.Redis --version 0.9.3
                    
NuGet\Install-Package Fluens.Messaging.Redis -Version 0.9.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fluens.Messaging.Redis" Version="0.9.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fluens.Messaging.Redis" Version="0.9.3" />
                    
Directory.Packages.props
<PackageReference Include="Fluens.Messaging.Redis" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fluens.Messaging.Redis --version 0.9.3
                    
#r "nuget: Fluens.Messaging.Redis, 0.9.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fluens.Messaging.Redis@0.9.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fluens.Messaging.Redis&version=0.9.3
                    
Install as a Cake Addin
#tool nuget:?package=Fluens.Messaging.Redis&version=0.9.3
                    
Install as a Cake Tool

Fluens.Messaging.Redis

Instance broadcast over Redis pub/sub for Fluens.Messaging: a message consumed once through the mesh and the inbox is handed to every live replica of the application, so in-process state (caches, local projections) can be invalidated on each replica.

Installation

dotnet add package Fluens.Messaging.Redis

Usage

There is no IFluensBuilder extension for Redis. The only opt-in is the nested callback on AddMessaging:

fluensBuilder.AddMessaging(o => o.AddRedisBroadcast());

AddRedisBroadcast binds Fluens:Messaging:Redis, applies the optional callback, validates the result and registers the broadcast transport, the broadcast dispatcher, the gap notifier and two hosted services (a startup check and the subscriber). It is a no-op when Enabled is false. Calling it twice registers each service once.

fluensBuilder.AddMessaging(o => o.AddRedisBroadcast(r =>
{
    r.ConnectionString = "localhost:6379";
}));

Replicas of one application also need a cluster identity: set Fluens:Web:Discovery:ClusterId to a non-blank value and call AddDiscovery(). A non-blank ClusterId registers IClusterIdentity, which the channel name is built from. A missing IClusterIdentity fails host start with an InvalidOperationException that names the setting.

Configuration

Section: Fluens:Messaging:Redis.

{
  "Fluens": {
    "Messaging": {
      "Redis": {
        "Enabled": true,
        "ConnectionString": "localhost:6379",
        "ChannelPrefix": "fluens",
        "DeduplicationWindowSeconds": 600,
        "DeduplicationCapacity": 10000
      }
    }
  }
}
Property Type Default Description
Enabled bool true When false, AddRedisBroadcast registers nothing.
ConnectionString string? null Redis connection string. Used only when no IConnectionMultiplexer is registered in DI; then it is required.
ChannelPrefix string "fluens" First segment of the broadcast channel name. Must not be blank.
DeduplicationWindowSeconds int 600 How long a received message id is remembered per module. Must be greater than 0.
DeduplicationCapacity int 10000 Maximum number of message ids remembered for deduplication. Must be greater than 0.

An invalid instance throws OptionsException<RedisBroadcastOptions>. A missing connection string throws the same exception when no multiplexer is registered in DI.

Leader lease

When the broadcast is enabled, the Redis broadcast also holds the leader lease of the replica (ILeaderLease). It takes precedence over a Consul lease from Fluens.Web.Discovery; with neither, every process is leader. The leader of the replica runs the messaging workers; see the Fluens.Messaging README (Deployment Scope).

Timing is bound from Fluens:Messaging:Redis:Leader:

Property Type Default Meaning
Leader.TtlSeconds int 30 How long the lease lives without a renewal. Must be greater than Leader.RetrySeconds.
Leader.RetrySeconds int 5 Pause between acquire attempts and between renewals. Must be greater than 0.
{
  "Fluens": {
    "Messaging": {
      "Redis": {
        "Leader": { "TtlSeconds": 30, "RetrySeconds": 5 }
      }
    }
  }
}
  • Lease key: {ChannelPrefix}:{ClusterId}:{UniqueKey}:leader, holding the owner id with the TTL. UniqueKey is the instance-unique identity key of the application (IApplicationIdentity.UniqueKey), so a replica has its own lease.
  • Release channel: {ChannelPrefix}:{ClusterId}:{UniqueKey}:leader-released. The owner that releases the lease publishes its owner id there; a waiting process wakes at once instead of after RetrySeconds.
  • Acquire, renew and release each run as one Lua script, so the owner check and the write are atomic. The lease needs a cluster identity, like the broadcast channel.
  • Processes of one application without a configured UniqueId share the unique key, and with it one lease.

Wake-up relay

When the broadcast is enabled it also registers the IWakeUpRelay of Fluens.Messaging, replacing any relay registered before it. A message written on a process that waits for the leader role then wakes the matching worker (transport, ingress or the inbox of its module) on the leader at once, instead of at the worker's polling interval; without Redis the wake-up stays local.

  • Wake channel: {ChannelPrefix}:{ClusterId}:{UniqueKey}:wake. It is scoped to one replica (IApplicationIdentity.UniqueKey), so a signal never reaches another replica.
  • A signal is a short text frame (transport, ingress or inbox:<module>). It is published fire-and-forget, a failed publish is logged as a warning, and a frame that is not a signal is ignored.
  • The channel resolves on first use and needs a cluster identity, like the broadcast channel; a missing one fails host start with the same message.
  • It shares the multiplexer of the broadcast.

Instance consumers

The broadcast is driven by IInstanceMessageConsumer<TMessage> in Fluens.Messaging. Register the consumer with SubscribesFromAssembly as for plain consumers; see the Fluens.Messaging README for the consumer contract, the relay inbox row and the deployment scope.

Connection reuse and channel naming

  • If an IConnectionMultiplexer is registered in DI, the broadcast publishes and subscribes through it.
  • Otherwise one multiplexer is connected lazily from ConnectionString, once, and shared by the publisher and the subscriber. It is disposed with the host.
  • The channel is {ChannelPrefix}:{ClusterId}:{ApplicationKey}:broadcast, for example fluens:cluster-1:orders:broadcast. Each replica of an application subscribes to the same channel; a different cluster or application never shares it.

Delivery semantics

  • The message reaches one replica through the mesh and that replica's inbox, which stay durable and deduplicated. The broadcast from the inbox row is then best effort.
  • The relay publishes the frame and acknowledges the inbox row after Redis accepts the publish. A transport failure leaves the row to the standard retry and dead-letter path. A publish that reached no subscriber is logged as a warning and still acknowledged.
  • Each replica deduplicates received frames by (message id, module) within the window and capacity above, so a frame delivered twice is handled once per replica.
  • A consumer that throws is logged and counted, is not retried, and does not stop the other consumers of the same frame.
  • Frames are handled one at a time per replica, in the order Redis delivers them.

Gap handling

The subscriber watches the subscription connection. When it is lost and then restored, the interval between the loss and the restore is a subscription gap. Every replica reports the gap to every IInstanceSubscriptionGapHandler it has registered. A gap handler is an instance-consumer type that also implements IInstanceSubscriptionGapHandler, so the module scan picks it up.

public sealed class CatalogGapHandler : IInstanceMessageConsumer<CatalogChangedMessage>, IInstanceSubscriptionGapHandler
{
    public Task ConsumeAsync(CatalogChangedMessage message, InstanceMessageContext context, CancellationToken cancellationToken) { /* invalidate */ return Task.CompletedTask; }

    public Task OnSubscriptionGapAsync(SubscriptionGap gap, CancellationToken cancellationToken) { /* drop the local state */ return Task.CompletedTask; }
}

Limitation: gap detection keys on the dedicated subscription connection. StackExchange.Redis 3.x negotiates RESP3 by default and still opens that dedicated connection under both RESP2 and RESP3. A multiplexer with SharedSubscriptionConnection enabled carries pub/sub on the interactive connection and reports no gaps; do not rely on gap handlers with that setting.

Startup

  • Startup connects to Redis and returns only once Redis has confirmed the subscription. An unreachable Redis therefore fails host start.
  • Registering the broadcast without a cluster identity or without a multiplexer or connection string fails host start.
  • Starting a host with instance consumers but without a broadcast transport fails start with a message naming AddRedisBroadcast().

Metrics

The broadcast records these instruments on the Fluens.Messaging meter. Add that meter to ObservabilityOptions.AdditionalMeters to export them.

Instrument Type Tags
broadcast.published counter module, message_type, has_receivers
broadcast.received counter module, message_type
broadcast.duplicate counter module, message_type
broadcast.handled counter module, handler_type
broadcast.failed counter module, handler_type, stage (decode, handle or gap)
broadcast.subscription_gap counter none

Constraints

  • Best effort. Redis pub/sub does not persist or replay. A replica that is down or disconnected misses the broadcast, and nothing re-sends it. The gap handler tells the replica that it may have missed messages; it does not recover them.
  • Derived or expiring state only. Use instance consumers for state that can be rebuilt or that expires on its own: caches, local projections. Do not use them for state that must be exact or durable. The durable path is the mesh and the inbox, not the broadcast.
  • One messaging database per replica. Each replica of an application owns its own messaging database (its own inbox, outbox and related tables). Replicas share the application identity key, so the mesh sees one application. Replicas must not point at the same messaging database.

License

This project is licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.4 96 11/30/2026
0.9.3 108 11/17/2026
0.9.2 126 10/21/2026
0.9.1 114 10/13/2026
0.9.0 102 10/13/2026