NATS.Client.Core 2.0.0-alpha.2

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

NATS.NET V2

Preview

The NATS.NET V2 client is in preview and not recommended for production use. Codebase is still under heavy development and currently we only have implementations for core NATS features.

Please test and provide feedback by visiting our Slack channel.

NATS.NET V2 Goals

  • Only support Async I/O
  • Target latest .NET LTS Release (currently net6.0)

Packages

  • NATS.Client.Core: core NATS
  • NATS.Client.Hosting: extension to configure DI container
  • NATS.Client.JetStream: JetStream not yet implemented

Basic Usage

Download the latest nats-server for your platform and run it without any arguments. nats-server will listen on its default TCP port 4222.

Given that we have a plain class Bar, we can publish and subscribe to our nats-server sending and receiving Bar objects:

public record Bar
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Subscribe to all bar related subjects:

await using var nats = new NatsConnection(options);

await using sub = await nats.SubscribeAsync<Bar>("bar.>");
await foreach (var msg in sub.Msgs.ReadAllAsync())
{
    Console.WriteLine($"Received {msg.Subject}: {msg.Data}\n");
}

Publish Bar objects to related bar subjects:

await using var nats = new NatsConnection();

for (int i = 0; i < 10; i++)
{
    Console.WriteLine($" Publishing {i}...");
    await nats.PublishAsync<Bar>($"bar.baz.{i}", new Bar { Id = i, Name = "Baz" });
}

You should also hook your logger to NatsConnection to make sure all is working as expected or to get help diagnosing any issues you might have:

var options = NatsOpts.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
await using var nats = new NatsConnection(options);

Contributing

  • Run dotnet format at root directory of project in order to clear warnings that can be auto-formatted

Attribution

This library is based on the excellent work in Cysharp/AlterNats

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (17)

Showing the top 5 NuGet packages that depend on NATS.Client.Core:

Package Downloads
NATS.Client.JetStream

JetStream support for NATS.Client.

NATS.Client.Services

Service API support for NATS.Client.

NATS.Net

NATS client for modern .NET

NATS.Client.Hosting

ASP.NET Core and Generic Host support for NATS.Client.

NATS.Client.Simplified

NATS simplified client for .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.7.2-preview.1 406 1/14/2026
2.7.1 20,720 1/8/2026
2.7.0 22,023 12/19/2025 2.7.0 is deprecated.
2.7.0-preview.8 2,828 10/20/2025
2.7.0-preview.7 495 10/1/2025
2.7.0-preview.6 987 9/22/2025
2.7.0-preview.5 679 9/2/2025
2.7.0-preview.4 1,525 8/21/2025
2.7.0-preview.3 211 8/1/2025
2.7.0-preview.2 1,033 7/21/2025
2.7.0-preview.1 614 7/18/2025
2.6.14 5,584 12/17/2025
2.6.12 20,523 12/11/2025
2.6.11 256,632 10/17/2025
2.6.10 96,620 10/1/2025
2.6.9 53,429 9/17/2025
2.6.8 177,532 9/2/2025
2.6.8-preview.1 194 8/28/2025
2.6.7 81,356 8/21/2025
2.6.6 79,000 8/1/2025
2.6.5 52,595 7/21/2025
2.6.4 83,063 7/16/2025
2.6.3 57,554 6/30/2025
2.6.2-preview.1 676 5/24/2025
2.6.1 312,711 5/13/2025
2.6.0 105,242 4/25/2025
2.6.0-preview.5 183 4/24/2025
2.6.0-preview.4 308 4/9/2025
2.6.0-preview.3 743 3/12/2025
2.6.0-preview.2 249 2/28/2025
2.6.0-preview.1 156 2/27/2025
2.5.16 41,883 4/16/2025
2.5.15 20,260 4/10/2025
2.5.14 1,903 4/9/2025
2.5.12 75,406 3/21/2025
2.5.11 82,534 3/12/2025
2.5.10 85,952 3/12/2025
2.5.10-preview.1 239 3/7/2025
2.5.9 64,203 2/24/2025
2.5.8 92,564 2/11/2025
2.5.8-preview.1 187 1/29/2025
2.5.7 59,832 1/27/2025
2.5.6 69,303 1/13/2025
2.5.5 425,963 12/10/2024
2.5.4 153,458 11/13/2024
2.5.3 65,860 11/5/2024
2.5.2 127,098 10/22/2024
2.5.1 244,042 10/17/2024
2.5.0 48,721 10/9/2024
2.5.0-preview.2 136 10/8/2024
2.5.0-preview.1 219 10/1/2024
2.4.0 76,452 9/17/2024
2.4.0-preview.3 159 9/11/2024
2.4.0-preview.2 204 8/23/2024
2.4.0-preview.1 32,854 8/5/2024
2.3.3 332,190 8/2/2024
2.3.3-preview.4 243 7/26/2024
2.3.3-preview.3 199 7/25/2024
2.3.3-preview.2 146 7/24/2024
2.3.3-preview.1 337 7/18/2024
2.3.2 109,162 7/10/2024
2.3.1 15,965 7/9/2024
2.3.1-preview.2 151 7/8/2024
2.3.1-preview.1 124 7/6/2024
2.3.0 62,119 7/3/2024
2.3.0-preview.1 718 6/24/2024
2.2.3 88,921 6/11/2024
2.2.2 36,410 5/23/2024
2.2.1 131,499 4/17/2024
2.2.0 28,382 4/4/2024
2.1.4 24,291 3/19/2024
2.1.3 6,220 3/12/2024
2.1.2 43,526 2/27/2024
2.1.1 7,059 2/20/2024
2.1.0 17,938 2/10/2024
2.1.0-preview.7 135 2/8/2024
2.1.0-preview.6 185 2/2/2024
2.1.0-preview.5 1,430 1/25/2024
2.1.0-preview.4 140 1/23/2024
2.1.0-preview.3 13,609 1/18/2024
2.1.0-preview.2 1,474 1/12/2024
2.1.0-preview.1 169 1/11/2024
2.0.3 108,050 1/5/2024
2.0.3-preview.1 706 12/22/2023
2.0.2 27,028 12/15/2023
2.0.2-preview.2 177 12/12/2023
2.0.2-preview.1 1,612 12/6/2023
2.0.1 18,191 11/29/2023
2.0.0 7,733 11/23/2023
2.0.0-rc.2 1,067 11/21/2023
2.0.0-rc.1 441 11/17/2023
2.0.0-beta.3 169 11/16/2023
2.0.0-beta.2 5,678 11/13/2023
2.0.0-beta.1 746 11/7/2023
2.0.0-beta.0 478 11/7/2023
2.0.0-alpha.7 706 10/27/2023
2.0.0-alpha.6 234 10/25/2023
2.0.0-alpha.5 292 10/20/2023
2.0.0-alpha.4 18,294 10/12/2023
2.0.0-alpha.3 431 9/13/2023
2.0.0-alpha.2 192 9/7/2023
2.0.0-alpha.1 215 8/31/2023
2.0.0-alpha.0 1,037 7/10/2023