NATS.Client.Hosting
2.5.5
Prefix Reserved
dotnet add package NATS.Client.Hosting --version 2.5.5
NuGet\Install-Package NATS.Client.Hosting -Version 2.5.5
<PackageReference Include="NATS.Client.Hosting" Version="2.5.5" />
paket add NATS.Client.Hosting --version 2.5.5
#r "nuget: NATS.Client.Hosting, 2.5.5"
// Install NATS.Client.Hosting as a Cake Addin #addin nuget:?package=NATS.Client.Hosting&version=2.5.5 // Install NATS.Client.Hosting as a Cake Tool #tool nuget:?package=NATS.Client.Hosting&version=2.5.5
NATS .NET
NATS .NET is a client library designed to connect to the NATS messaging server, fully supporting all NATS features. It integrates seamlessly with modern .NET asynchronous interfaces such as async enumerables and channels, and leverages advanced .NET memory, buffer and IO features.
Check out NATS .NET client library documentation for guides and examples.
[!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.
Head over to NATS documentation for more information.
Quick Start
Install the NATS.Net package from NuGet:
dotnet add package NATS.Net
Run a local nats-server
to use or connect to the demo server if you're not behind a firewall:
await using var client = new NatsClient("demo.nats.io");
Basic messaging:
// NATS core M:N messaging example
await using var client = new NatsClient();
// Subscribe on one terminal
await foreach (var msg in client.SubscribeAsync<string>(subject: "foo"))
{
Console.WriteLine($"Received: {msg.Data}");
}
// Start publishing to the same subject on a second terminal
await client.PublishAsync(subject: "foo", data: "Hello, World!");
Persistence with JetStream:
For this you need to run the server with JetStream enabled if you're using a local server.
// NATS JetStream basic publish-consume example
await using var client = new NatsClient();
var js = client.CreateJetStreamContext();
// Create a stream to store the messages
await js.CreateStreamAsync(new StreamConfig(name: "ORDERS", subjects: new[] { "orders.*" }));
// Publish a message to the stream. The message will be stored in the stream
// because the published subject matches one of the the stream's subjects.
var ack = await js.PublishAsync(subject: "orders.new", data: "order 1");
ack.EnsureSuccess();
// Create a consumer on a stream to receive the messages
var consumer = await js.CreateOrUpdateConsumerAsync("ORDERS", new ConsumerConfig("order_processor"));
await foreach (var jsMsg in consumer.ConsumeAsync<string>())
{
Console.WriteLine($"Processed: {jsMsg.Data}");
await jsMsg.AckAsync();
}
See more details, including how to download and start NATS server and JetStream in our documentation.
Additionally check out NATS by example - An evolving collection of runnable, cross-client reference examples for NATS.
NATS .NET Goals
- Only support Async I/O (async/await)
- Target .NET Standard 2.0, 2.1, and .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
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
#dotnet
channel - Join the discussion on GitHub Discussions
- Follow us on X @nats_io
Contributing Code
- Read the Contributor Guide
- Fork the repository and create a branch
- Open
NATS.Net.sln
solution 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.Tests
which is a subset of tests that should pass on Windows - You can also locally run
NATS.Client.CoreUnit.Tests
andNATS.Client.Core2.Tests
which are more stable - Run
dotnet format
at root directory of project to clear warnings that can be auto-formatted - Run
dotnet build
at 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. |
.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
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- NATS.Client.Core (>= 2.5.5)
-
.NETStandard 2.1
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- NATS.Client.Core (>= 2.5.5)
-
net6.0
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- NATS.Client.Core (>= 2.5.5)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- NATS.Client.Core (>= 2.5.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NATS.Client.Hosting:
Package | Downloads |
---|---|
NATS.Net
NATS client for modern .NET |
|
Core.ServiceMesh
.NET nats based services mesh and streams |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.5.5 | 6,057 | 12/10/2024 |
2.5.4 | 21,217 | 11/13/2024 |
2.5.3 | 17,789 | 11/5/2024 |
2.5.2 | 15,965 | 10/22/2024 |
2.5.1 | 21,540 | 10/17/2024 |
2.5.0 | 16,180 | 10/9/2024 |
2.5.0-preview.2 | 59 | 10/8/2024 |
2.5.0-preview.1 | 119 | 10/1/2024 |
2.4.0 | 19,887 | 9/17/2024 |
2.4.0-preview.3 | 79 | 9/11/2024 |
2.4.0-preview.2 | 105 | 8/23/2024 |
2.4.0-preview.1 | 2,275 | 8/5/2024 |
2.3.3 | 67,431 | 8/2/2024 |
2.3.3-preview.4 | 166 | 7/26/2024 |
2.3.3-preview.3 | 116 | 7/25/2024 |
2.3.3-preview.2 | 61 | 7/24/2024 |
2.3.3-preview.1 | 189 | 7/18/2024 |
2.3.2 | 33,146 | 7/10/2024 |
2.3.1 | 3,008 | 7/9/2024 |
2.3.1-preview.2 | 73 | 7/8/2024 |
2.3.1-preview.1 | 60 | 7/6/2024 |
2.3.0 | 21,662 | 7/3/2024 |
2.3.0-preview.1 | 123 | 6/24/2024 |
2.2.3 | 25,526 | 6/11/2024 |
2.2.2 | 16,836 | 5/23/2024 |
2.2.1 | 69,273 | 4/17/2024 |
2.2.0 | 15,090 | 4/4/2024 |
2.1.4 | 19,056 | 3/19/2024 |
2.1.3 | 4,991 | 3/12/2024 |
2.1.2 | 26,164 | 2/27/2024 |
2.1.1 | 4,370 | 2/20/2024 |
2.1.0 | 14,922 | 2/10/2024 |
2.1.0-preview.7 | 78 | 2/8/2024 |
2.1.0-preview.6 | 93 | 2/2/2024 |
2.1.0-preview.5 | 1,326 | 1/25/2024 |
2.1.0-preview.4 | 63 | 1/23/2024 |
2.1.0-preview.3 | 175 | 1/18/2024 |
2.1.0-preview.2 | 1,191 | 1/12/2024 |
2.1.0-preview.1 | 80 | 1/11/2024 |
2.0.3 | 70,487 | 1/5/2024 |
2.0.3-preview.1 | 434 | 12/22/2023 |
2.0.2 | 3,249 | 12/15/2023 |
2.0.2-preview.2 | 87 | 12/12/2023 |
2.0.2-preview.1 | 1,279 | 12/6/2023 |
2.0.1 | 17,006 | 11/29/2023 |
2.0.0 | 1,454 | 11/23/2023 |
2.0.0-rc.2 | 80 | 11/21/2023 |
2.0.0-rc.1 | 336 | 11/17/2023 |
2.0.0-beta.3 | 69 | 11/16/2023 |
2.0.0-beta.2 | 164 | 11/13/2023 |
2.0.0-beta.1 | 78 | 11/7/2023 |
2.0.0-beta.0 | 76 | 11/7/2023 |
2.0.0-alpha.7 | 159 | 10/27/2023 |
2.0.0-alpha.6 | 108 | 10/25/2023 |
2.0.0-alpha.5 | 225 | 10/20/2023 |
2.0.0-alpha.4 | 101 | 10/12/2023 |
2.0.0-alpha.3 | 206 | 9/13/2023 |
2.0.0-alpha.2 | 85 | 9/7/2023 |
2.0.0-alpha.1 | 92 | 8/31/2023 |
2.0.0-alpha.0 | 800 | 7/10/2023 |