NATS.Net
2.8.0
Prefix Reserved
See the version list below for details.
dotnet add package NATS.Net --version 2.8.0
NuGet\Install-Package NATS.Net -Version 2.8.0
<PackageReference Include="NATS.Net" Version="2.8.0" />
<PackageVersion Include="NATS.Net" Version="2.8.0" />
<PackageReference Include="NATS.Net" />
paket add NATS.Net --version 2.8.0
#r "nuget: NATS.Net, 2.8.0"
#:package NATS.Net@2.8.0
#addin nuget:?package=NATS.Net&version=2.8.0
#tool nuget:?package=NATS.Net&version=2.8.0
NATS .NET
NATS .NET is the .NET client for NATS, a distributed messaging system. It provides pub/sub and request/reply (Core NATS), streaming and persistence (JetStream), Key-Value Store, Object Store, and Services.
Check out DOCS for guides and examples.
Additionally check out NATS by example - An evolving collection of runnable, cross-client reference examples for NATS.
Quick Start
Start a NATS server:
docker run -p 4222:4222 nats
Create a subscriber app:
dotnet new console -n Sub && cd Sub && dotnet add package NATS.Net
using NATS.Net;
await using var nc = new NatsClient();
await foreach (var msg in nc.SubscribeAsync<string>("greet"))
Console.WriteLine($"Received: {msg.Data}");
In another terminal, create a publisher app:
dotnet new console -n Pub && cd Pub && dotnet add package NATS.Net
using NATS.Net;
await using var nc = new NatsClient();
await nc.PublishAsync("greet", "Hello, NATS!");
API at a Glance
using NATS.Net;
await using var nc = new NatsClient();
// Publish a message
await nc.PublishAsync("orders.new", new Order(Id: 1, Item: "widget"));
// Subscribe with async enumerable
await foreach (var msg in nc.SubscribeAsync<Order>("orders.>"))
Console.WriteLine($"Received order: {msg.Data}");
// Request-reply
var order = new Order(Id: 2, Item: "gadget");
var reply = await nc.RequestAsync<Order, Confirmation>("orders.create", order);
// JetStream (persistent messaging)
var js = nc.CreateJetStreamContext();
// Key/Value Store
var kv = nc.CreateKeyValueStoreContext();
// Object Store
var obj = nc.CreateObjectStoreContext();
// Services
var svc = nc.CreateServicesContext();
We are not testing with .NET 6.0 target anymore even though it is still targeted by the library. This is to reduce the number of test runs and speed up the CI process as well as to prepare for the next major version, possibly dropping .NET 6.0 support.
Don't confuse NuGet packages!
NATS .NET package on NuGet is called NATS.Net.
There is another package called NATS.Client which is the older version of the client library
and will be deprecated eventually.
NATS .NET now supports .NET Standard 2.0 and 2.1 along with .NET 6.0 and 8.0, which means you can also use it with .NET Framework 4.6.2+ and Unity 2018.1+.
What is NATS?
NATS is a high-performance, secure, distributed messaging system. It's a connective technology tailored for modern distributed systems, facilitating efficient addressing, discovery, and message exchange. It supports dynamic service and stream processing across various locations and devices, enhancing mobility, security, and independence from traditional constraints such as DNS.
Head over to NATS documentation for more information.
NATS .NET Goals
- Only support Async I/O (async/await)
- Target .NET Standard 2.0, 2.1, and the two most recent .NET LTS releases (currently .NET 6.0 & .NET 8.0)
Packages
- NATS.Net: Meta package that includes all other packages except extensions
- NATS.Client.Core: Core NATS
- NATS.Client.JetStream: JetStream
- NATS.Client.KeyValueStore: Key/Value Store
- NATS.Client.ObjectStore: Object Store
- NATS.Client.Services: Services
- NATS.Client.Simplified: simplify common use cases especially for beginners
- NATS.Client.Serializers.Json: JSON serializer for ad-hoc types
- NATS.Extensions.Microsoft.DependencyInjection: extension to configure DI container
Client and Orbit
NATS client functionality is split across two layers: the core client
(NATS.Net, this repo) and Orbit,
a separate set of packages with higher-level utilities.
The split exists so the core can stay small, stable, and consistent across NATS clients in every language, while Orbit can iterate quickly on opinionated abstractions without dragging the core API along for the ride.
Core client (NATS.Net)
- Direct API over Core NATS and JetStream as exposed by
nats-server. - Lightweight, unopinionated, performance-oriented.
- API surface kept in parity with other official NATS clients (Rust, Go, Java, JS, Python, C). A feature shipped here should look the same shape everywhere.
- Stable, conservative versioning. Breaking changes are rare and deliberate.
Orbit (orbit.net)
- Higher-level, opinionated abstractions built on top of the core client.
- Per-package versioning, so an experimental utility can iterate without bumping every other piece.
- Free to be language-specific: a .NET-idiomatic API does not need to match the equivalent in other languages.
- May lag, omit, or extend cross-client parity items.
What goes where?
| Concern | Core (NATS.Net) |
Orbit |
|---|---|---|
| Connect, publish, subscribe, request/reply | ✅ | |
| JetStream publish, consumers, streams, KV, OS | ✅ | |
| Service API (request/reply micro-services) | ✅ | |
| Wire-protocol coverage, auth, TLS, reconnection | ✅ | |
| Cross-client parity, conservative semver | ✅ | |
| Opinionated helpers / sugar over core APIs | ✅ | |
| New experimental patterns (e.g. partitioned groups) | ✅ | |
| KV codecs, distributed counters, NATS contexts | ✅ | |
| .NET-idiomatic abstractions with no parity mandate | ✅ | |
| Per-utility versioning, faster API churn allowed | ✅ |
Rule of thumb: if it is a thin mapping of something
nats-serveralready speaks and every official client must expose it, it belongs in core. If it is a pattern, helper, or abstraction layered on top, it belongs in Orbit.
Layering
┌──────────────────────────────────────────────────────┐
│ Application code │
└──────────────┬───────────────────────────┬───────────┘
│ │
▼ ▼
┌───────────────────┐ ┌───────────────────┐
│ Orbit packages │ uses │ NATS.Net (core) │
│ (opinionated, │──────▶│ (parity, stable, │
│ per-pkg semver) │ │ protocol-level) │
└───────────────────┘ └─────────┬─────────┘
│
▼
┌─────────────┐
│ nats-server │
└─────────────┘
Contributing
You are welcome to contribute to this project. Here are some steps to get you started:
Reporting Bugs and Feature Requests
You can report bugs and request features by opening an issue on GitHub.
Join the Community
You can join the community asking questions, sharing ideas, and helping others:
- Join the NATS Slack and find us on the
#dotnetchannel - Join the discussion on GitHub Discussions
- Follow us on X @nats_io
Contributing Code
Please make sure to sign your commits. All commits must be signed before a Pull Request can be merged.
- Read the Contributor Guide
- Fork the repository and create a branch
- Open
NATS.Net.slnxsolution in Visual Studio, Rider or VS Code (or any other editor of your choice) - Make changes and write tests
- Run tests against a locally installed NATS server in your PATH
- Note that some tests are still not reliable locally, so CI will run all tests
- For a quick check, run
NATS.Client.Platform.Windows.Testswhich is a subset of tests that should pass on Windows - You can also locally run
NATS.Client.CoreUnit.TestsandNATS.Client.Core2.Testswhich are more stable - Run
dotnet formatat root directory of project to clear warnings that can be auto-formatted - Run
dotnet buildat root directory and make sure there are no errors or warnings - Submit a pull request
Please also check out the Contributor Guide and Code of Conduct.
Attribution
This library is based on the excellent work in Cysharp/AlterNats
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- NATS.Client.Core (>= 2.8.0)
- NATS.Client.Hosting (>= 2.8.0)
- NATS.Client.JetStream (>= 2.8.0)
- NATS.Client.KeyValueStore (>= 2.8.0)
- NATS.Client.ObjectStore (>= 2.8.0)
- NATS.Client.Serializers.Json (>= 2.8.0)
- NATS.Client.Services (>= 2.8.0)
- NATS.Client.Simplified (>= 2.8.0)
-
.NETStandard 2.1
- NATS.Client.Core (>= 2.8.0)
- NATS.Client.Hosting (>= 2.8.0)
- NATS.Client.JetStream (>= 2.8.0)
- NATS.Client.KeyValueStore (>= 2.8.0)
- NATS.Client.ObjectStore (>= 2.8.0)
- NATS.Client.Serializers.Json (>= 2.8.0)
- NATS.Client.Services (>= 2.8.0)
- NATS.Client.Simplified (>= 2.8.0)
-
net6.0
- NATS.Client.Core (>= 2.8.0)
- NATS.Client.Hosting (>= 2.8.0)
- NATS.Client.JetStream (>= 2.8.0)
- NATS.Client.KeyValueStore (>= 2.8.0)
- NATS.Client.ObjectStore (>= 2.8.0)
- NATS.Client.Serializers.Json (>= 2.8.0)
- NATS.Client.Services (>= 2.8.0)
- NATS.Client.Simplified (>= 2.8.0)
-
net8.0
- NATS.Client.Core (>= 2.8.0)
- NATS.Client.Hosting (>= 2.8.0)
- NATS.Client.JetStream (>= 2.8.0)
- NATS.Client.KeyValueStore (>= 2.8.0)
- NATS.Client.ObjectStore (>= 2.8.0)
- NATS.Client.Serializers.Json (>= 2.8.0)
- NATS.Client.Services (>= 2.8.0)
- NATS.Client.Simplified (>= 2.8.0)
NuGet packages (65)
Showing the top 5 NuGet packages that depend on NATS.Net:
| Package | Downloads |
|---|---|
|
AspNetCore.HealthChecks.Nats
HealthChecks.Nats is the health check package for Nats. |
|
|
OpenTAP.Runner.Client
This is the C# Client for the OpenTAP Runner. |
|
|
Aspire.Hosting.Nats
NATS support for Aspire. |
|
|
Aspire.NATS.Net
A NATS client that integrates with Aspire, including health checks and logging. |
|
|
AgoraIoT.Edge.App.SDK
SDK for creation of Agora Edge Applications. |
GitHub repositories (8)
Showing the top 8 popular GitHub repositories that depend on NATS.Net:
| Repository | Stars |
|---|---|
|
dotnet/orleans
Cloud Native application framework for .NET
|
|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
|
|
JasperFx/wolverine
Supercharged .NET server side development!
|
|
|
minio/minio-dotnet
MinIO Client SDK for .NET
|
|
|
zarusz/SlimMessageBus
Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
|
|
|
osstotalsoft/nbb
.Net Building Blocks
|
|
|
NimbusAPI/Nimbus
Nimbus is a .NET client library to provide an easy abstraction over common messaging frameworks.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 3.0.0-preview.5 | 89 | 5/7/2026 | |
| 3.0.0-preview.4 | 456 | 5/1/2026 | |
| 3.0.0-preview.3 | 771 | 4/17/2026 | |
| 3.0.0-preview.2 | 1,691 | 3/13/2026 | |
| 3.0.0-preview.1 | 899 | 2/18/2026 | |
| 2.8.0 | 0 | 5/13/2026 | |
| 2.8.0-preview.3 | 51 | 5/6/2026 | |
| 2.8.0-preview.2 | 182 | 5/1/2026 | |
| 2.8.0-preview.1 | 124 | 4/16/2026 | |
| 2.7.3 | 204,849 | 3/13/2026 | |
| 2.7.2 | 221,840 | 2/10/2026 | |
| 2.7.2-preview.2 | 491 | 1/30/2026 | |
| 2.7.2-preview.1 | 1,369 | 1/14/2026 | |
| 2.7.1 | 118,089 | 1/8/2026 | |
| 2.7.0 | 53,110 | 12/19/2025 | |
| 2.7.0-preview.8 | 4,335 | 10/20/2025 | |
| 2.7.0-preview.7 | 455 | 10/1/2025 | |
| 2.6.14 | 23,213 | 12/17/2025 | |
| 2.6.12 | 20,099 | 12/11/2025 | |
| 2.6.11 | 726,272 | 10/17/2025 |