redb.Route.WebSocket 4.0.0

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

redb.Route.WebSocket

WebSocket transport for redb.Route. ClientWebSocket producer and Kestrel-based WebSocket server consumer with text/binary frames, ping/pong, reconnect, and subprotocol support.

NuGet License: Apache 2.0

Installation

dotnet add package redb.Route.WebSocket

Usage

Fluent DSL

using redb.Route.WebSocket.Fluent;

// WebSocket server (consumer)
From(Ws.Listen("0.0.0.0:8080/ws")
        .MaxConnections(500)
        .InOut())
    .Process(async (e, ct) =>
    {
        var msg = e.Message.GetBody<string>();
        e.Message.SetBody($"Echo: {msg}");
    });

// WebSocket client (producer)
From("direct://push")
    .To(Ws.Connect("wss://stream.example.com/feed")
        .SubProtocol("json")
        .ConnectTimeout(5000)
        .Reconnect(intervalMs: 3000, maxAttempts: 10));

// Binary mode
From(Ws.Listen("0.0.0.0:8080/binary")
        .Binary()
        .ReceiveBufferSize(65536))
    .To("direct://binary-handler");

// TLS
From(Ws.Listen("0.0.0.0:8443/secure")
        .Ssl()
        .SslCertPath("/certs/server.pfx")
        .SslCertPassword("password"))
    .To("direct://secure-handler");

Fluent Builder API

Category Methods
Server Ws.Listen(hostPortPath), .MaxConnections(), .InOut()
Client Ws.Connect(hostPortPath), .ConnectTimeout(), .Reconnect(interval, max)
Framing .Binary(), .Encoding(), .SubProtocol()
Socket .ReceiveBufferSize(), .SendBufferSize(), .KeepAliveInterval()
TLS .Ssl(), .SslCertPath(), .SslCertPassword(), .TrustAllCertificates()

One port for REST and WebSocket

The consumer serves on the shared Kestrel host (redb.Route.Http.Hosting), the same listener HTTP, gRPC, SOAP and AS2 routes use, so the typical production layout works:

From("http://0.0.0.0:8080/api/orders")   // REST
From("ws://0.0.0.0:8080/stream")         // live updates, same port, same proxy

Pushing to connected clients

A route can send frames to its own clients instead of only answering them (mode=Server / Ws.Broadcast):

// broadcast to everyone on /stream
From("timer://ticks?period=1000")
    .To(Ws.Broadcast("0.0.0.0:8080/stream"));

// answer one client later, by the id the incoming exchange carried
From(Ws.Listen("0.0.0.0:8080/stream"))
    .To("direct://slow-work");

From("direct://slow-work-done")
    .SetHeader(WsHeaders.TargetConnection, Simple("${header.redbWs.ConnectionId}"))
    .To(Ws.Broadcast("0.0.0.0:8080/stream"));

The consumer serving that address has to be running; a server-mode producer that finds none refuses to start rather than pushing into nothing.

Authenticating the handshake

The route host is a generic host, not an ASP.NET application, so the host supplies a delegate:

services.AddRedbRouteWebSocket(o => o.Authenticate = async ctx =>
    await myJwtValidator.ValidateAsync(ctx.Request.Query["access_token"]));

Null rejects the upgrade with 401. The principal's NameIdentifier reaches the route as the redbWs.UserId header.

Schemes

Both ws and wss schemes are supported for plain and TLS connections. wss:// on a consumer requires sslCertPath: without it the listener would be a plain socket while the log said wss://, so it refuses to start. On a producer, reaching a server with a self-signed certificate (staging) needs an explicit trustAllCertificates=true.

Behaviour worth knowing

  • maxConnections queues, it does not refuse. A client arriving over the limit waits for a slot instead of being rejected, and gives up when it disconnects.
  • inOut has no correlation id. WebSocket is duplex, so the first frame that arrives after a send is taken as its answer; an unrelated server push landing at that moment would be taken instead. The send lock is held while waiting, which also serialises senders.
  • reconnect=true retries forever by default (maxReconnectAttempts=0). Against a server that stays down that means an exchange never returns and dead-letter never fires — set reconnectTimeout (ms) to cap the attempts by time and let the send fail.

Part of

redb.Route — ESB & EIP Framework for .NET

Named connection factory

Keep credentials out of the route URI: register a factory in the context registry and reference it by name. A set-but-unknown name fails loud at startup — a typo can never silently fall back to inline URI parameters.

context.AddToRegistry("prod", new WsConnectionFactory
{
    Ssl = true,
    SslCertPath = "/secrets/client.pfx",
});
// wss://feed.internal/ticks?connectionFactory=prod
Product Compatible and additional computed target framework versions.
.NET 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 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
4.0.1 46 9/18/2026
4.0.0 93 9/11/2026
3.7.2 110 8/26/2026
3.7.1 106 8/26/2026
3.6.0 116 8/13/2026
3.5.1 106 8/9/2026
3.5.0 122 8/6/2026
3.4.0 113 7/27/2026
3.3.3 137 7/16/2026
3.3.1 140 7/10/2026
3.3.0 119 7/8/2026
3.2.0 146 6/29/2026
3.1.0 131 6/6/2026
3.0.1 123 6/3/2026
3.0.0 122 5/29/2026
2.0.2 128 5/16/2026
2.0.0 83 5/6/2026