Fluens.Messaging.Redis 0.9.1

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.1
                    
NuGet\Install-Package Fluens.Messaging.Redis -Version 0.9.1
                    
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.1" />
                    
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.1" />
                    
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.1
                    
#r "nuget: Fluens.Messaging.Redis, 0.9.1"
                    
#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.1
                    
#: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.1
                    
Install as a Cake Addin
#tool nuget:?package=Fluens.Messaging.Redis&version=0.9.1
                    
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.

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 subscription connection under the RESP2 default. A multiplexer configured for RESP3 carries pub/sub on the interactive connection and reports no gaps; do not rely on gap handlers with RESP3.

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