GobanSource.Bus.Redis 1.0.42

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package GobanSource.Bus.Redis --version 1.0.42
                    
NuGet\Install-Package GobanSource.Bus.Redis -Version 1.0.42
                    
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="GobanSource.Bus.Redis" Version="1.0.42" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GobanSource.Bus.Redis" Version="1.0.42" />
                    
Directory.Packages.props
<PackageReference Include="GobanSource.Bus.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 GobanSource.Bus.Redis --version 1.0.42
                    
#r "nuget: GobanSource.Bus.Redis, 1.0.42"
                    
#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 GobanSource.Bus.Redis@1.0.42
                    
#: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=GobanSource.Bus.Redis&version=1.0.42
                    
Install as a Cake Addin
#tool nuget:?package=GobanSource.Bus.Redis&version=1.0.42
                    
Install as a Cake Tool

GobanSource.Bus.Redis

build coverage NuGet MyGet Version License

A lightweight, Redis-based message bus library for .NET applications. Enables communication between distributed application instances using Redis Pub/Sub.

Features

  • True Fan-Out Messaging: Each message is delivered to all active subscribers across different application instances
  • Instance Filtering: Messages from the same instance are automatically skipped
  • Type-Safe Message Handling: Generic interfaces for strongly-typed message processing
  • Optional LZ4 Compression: Reduce bandwidth usage with fast LZ4 compression (backward compatible)
  • No Message Persistence: Only active subscribers receive messages (suitable for cache synchronization)
  • Easy Integration: Works with .NET's dependency injection and hosted services

Installation

dotnet add package GobanSource.Bus.Redis

Requirements

  • .NET Standard 2.0+
  • Redis server

Quick Start

1. Define your message type

public class SimpleMessage : BaseMessage
{
    public string Data { get; set; } = null!;
}

2. Create a message handler

public class SimpleMessageHandler : IMessageHandler<SimpleMessage>
{
    private readonly ILogger<SimpleMessageHandler> _logger;

    public SimpleMessageHandler(ILogger<SimpleMessageHandler> logger)
    {
        _logger = logger;
    }

    public async Task HandleAsync(SimpleMessage message)
    {
        _logger.LogInformation("Received message: {Data}", message.Data);
        // Process the message here
        await Task.CompletedTask;
    }
}

3. Register services in your application

// Add Redis connection
services.AddSingleton<IConnectionMultiplexer>(sp =>
    ConnectionMultiplexer.Connect("localhost:6379"));

// Register the message bus for SimpleMessage
services.AddTransient<IRedisSyncBus<SimpleMessage>>(sp => new RedisSyncBus<SimpleMessage>(
    sp.GetRequiredService<IConnectionMultiplexer>(),
    "messages",  // Channel prefix
    sp.GetRequiredService<ILogger<RedisSyncBus<SimpleMessage>>>(),
    false));     // Enable compression (optional, defaults to false)

// Register the message handler
services.AddTransient<IMessageHandler<SimpleMessage>, SimpleMessageHandler>();

// Register the hosted service that connects the bus to the handler
services.AddHostedService<MessageSyncHostedService<SimpleMessage>>();

4. Publish messages

public class MessagePublisher
{
    private readonly IRedisSyncBus<SimpleMessage> _bus;

    public MessagePublisher(IRedisSyncBus<SimpleMessage> bus)
    {
        _bus = bus;
    }

    public async Task SendMessageAsync(string data)
    {
        await _bus.PublishAsync(new SimpleMessage
        {
            Data = data
        });
    }
}

Compression

GobanSource.Bus.Redis supports optional LZ4 compression to reduce bandwidth usage and improve performance for large messages.

Enabling Compression

// Enable compression when creating the bus
services.AddTransient<IRedisSyncBus<SimpleMessage>>(sp => new RedisSyncBus<SimpleMessage>(
    sp.GetRequiredService<IConnectionMultiplexer>(),
    "messages",
    sp.GetRequiredService<ILogger<RedisSyncBus<SimpleMessage>>>(),
    enableCompression: true));  // Enable LZ4 compression

Features

  • LZ4 Frame Format: Fast compression/decompression with good compression ratios
  • Automatic Detection: Compressed and uncompressed messages are automatically detected
  • Backward Compatibility: Applications with compression enabled can communicate with those without
  • Performance Benefits: Especially effective for repetitive content or large messages
  • Transparent Operation: No changes needed to message handlers or publishers

When to Use Compression

  • Large Messages: Messages over 1KB typically benefit from compression
  • Repetitive Content: JSON with repeated structures compress very well
  • High-Volume Applications: Reduces Redis bandwidth and network traffic
  • Mixed Environments: Safe to enable during gradual rollouts

How It Works

GobanSource.Bus.Redis uses Redis Pub/Sub channels to publish and subscribe to messages between different application instances. When a message is published:

  1. The message is serialized to JSON
  2. If compression is enabled, the JSON is compressed using LZ4 Frame format
  3. The message (compressed or uncompressed) is published to a Redis channel: {prefix}:{messageType}
  4. Redis broadcasts the message to all subscribers of that channel
  5. Each subscriber automatically detects and decompresses the message if needed
  6. Messages from the same instance (identified by InstanceId) are automatically skipped

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Product 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 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on GobanSource.Bus.Redis:

Package Downloads
GobanSource.ReplicatedLruCache

A lightweight, replicated LRU cache library for .NET applications. replicated by redis pub/sub.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.44 141 7/11/2025
1.0.42 263 6/16/2025
1.0.40 129 6/15/2025
1.0.38 199 6/14/2025
0.1.2.29 277 6/13/2025
0.1.2.26 144 4/25/2025
0.1.2.23 193 4/15/2025
0.1.2.21 197 4/15/2025
0.1.2.19-pre 208 4/15/2025
0.1.2.17 195 4/15/2025
0.1.2.16 203 4/14/2025
0.1.2 201 4/14/2025
0.1.1 219 4/14/2025
0.1.0 148 4/12/2025