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.
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();
[!NOTE]
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.
[!NOTE]
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.
[!TIP]
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.
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:
Create a subscriber app:
In another terminal, create a publisher app:
API at a Glance
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
Packages
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:
#dotnetchannelContributing Code
NATS.Net.slnsolution in Visual Studio, Rider or VS Code (or any other editor of your choice)NATS.Client.Platform.Windows.Testswhich is a subset of tests that should pass on WindowsNATS.Client.CoreUnit.TestsandNATS.Client.Core2.Testswhich are more stabledotnet formatat root directory of project to clear warnings that can be auto-formatteddotnet buildat root directory and make sure there are no errors or warningsPlease also check out the Contributor Guide and Code of Conduct.
Attribution
This library is based on the excellent work in Cysharp/AlterNats