cloops.nats
1.1.6
dotnet add package cloops.nats --version 1.1.6
NuGet\Install-Package cloops.nats -Version 1.1.6
<PackageReference Include="cloops.nats" Version="1.1.6" />
<PackageVersion Include="cloops.nats" Version="1.1.6" />
<PackageReference Include="cloops.nats" />
paket add cloops.nats --version 1.1.6
#r "nuget: cloops.nats, 1.1.6"
#:package cloops.nats@1.1.6
#addin nuget:?package=cloops.nats&version=1.1.6
#tool nuget:?package=cloops.nats&version=1.1.6
CLOOPS NATS SDK
A modern, annotation-based SDK for building reliable distributed systems with NATS. Define your message consumers with simple attributes and let the framework handle the complexity.
Why NATS?
NATS is a powerful messaging system that enables you to build sophisticated, fault-tolerant distributed systems that are location-transparent and globally distributed.
- Faster than HTTP - Binary protocol with lower overhead
- Fewer hops - Direct communication without load balancers or API gateways
- Globally distributed - Deploy applications worldwide without DNS or complex load balancing. Learn more about NATS super clusters
π‘ Learn more: Check out this podcast from nats.fm for insights into NATS architecture.
Why This SDK?
Modern developers expect annotation-based definitions and dependency injectionβthe same developer experience you get with REST frameworks like ASP.NET Core. This SDK brings that same simplicity to NATS, so you can focus on your business logic instead of boilerplate.
What You Get
- β¨ Annotation-based consumers - Define subscribers with simple attributes
- π‘οΈ Built-in backpressure - Automatic handling of traffic spikes
- βοΈ Flexible load balancing - Choose between broadcasting or load balancing strategies
- π JetStream support - Build temporally decoupled systems with persistent messaging
- π§ Dependency injection - Seamless integration with .NET's DI container
- β
Automatic message validation - Messages with a
Validate()method are automatically validated before processing. Invalid messages are never sent to your handlers
π― Building microservices? Check out our microservices-focused SDK built on top of
cloops.natsand makes building microservices a breeze!
Quick Start
Installation
Add the cloops.nats package to your .csproj file:
<PackageReference Include="cloops.nats" Version="*" />
Run dotnet restore to install the package.
π‘ Tip: For Connection Loops standard messages and subjects, you may also need
cloops.nats.schema.
Examples
Broadcast Pattern (Kubernetes/Docker)
Ensure each pod/instance receives all messages by using runtime placeholders in the queue group name:
/// <summary>
/// Broadcast: Each pod gets a unique queue group, so all pods receive all messages
/// Supported placeholders: {POD_NAME}, {HOSTNAME}, {MACHINE_NAME}, {ENV:VAR_NAME}
/// </summary>
[NatsConsumer("test.broadcast", QueueGroupName = "pod-{POD_NAME}")]
public Task<NatsAck> BroadcastHandler(NatsMsg<string> msg, CancellationToken ct = default)
{
Console.WriteLine($"[Pod {Environment.GetEnvironmentVariable("POD_NAME")}] Received: {msg.Data}");
return Task.FromResult(new NatsAck(true));
}
Load Balancing Pattern
Distribute messages across multiple instances using the same queue group:
[NatsConsumer("test.lb", QueueGroupName = "workers")]
public async Task<NatsAck> HandleMessage(NatsMsg<string> msg, CancellationToken ct = default)
{
Console.WriteLine($"Instance received: {msg.Data}");
await Task.Delay(100, ct).ConfigureAwait(false); // Simulate work
return new NatsAck(true);
}
Runtime Placeholders
The SDK resolves placeholders dynamically:
{POD_NAME}βPOD_NAMEenv var, falls back toHOSTNAMEor machine name{HOSTNAME}βHOSTNAMEenv var, falls back to machine name{MACHINE_NAME}β Machine name{ENV:VAR_NAME}β Any environment variable (e.g.,{ENV:MY_CUSTOM_VAR})
π Note:
QueueGroupNameis optional. If omitted, an empty string is used, which still enables load balancing. JetStream subscriptions are always load-balanced (no broadcast support).
Learn More
- π Examples - See real-world usage patterns
- π Full Documentation - Detailed guides, setup instructions, and API reference
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on cloops.nats:
| Package | Downloads |
|---|---|
|
cloops.microservices
Opinionated SDK to effortlessly build lean highly performant cloud native microservices |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.6 | 4,059 | 12/14/2025 |
| 1.1.5 | 188 | 12/14/2025 |
| 1.1.4 | 182 | 12/14/2025 |
| 1.1.3 | 138 | 12/14/2025 |
| 1.1.2 | 131 | 12/14/2025 |
| 1.1.1 | 141 | 12/13/2025 |
| 1.0.42 | 341 | 11/17/2025 |
| 1.0.41 | 257 | 11/9/2025 |
| 1.0.40 | 186 | 11/9/2025 |
| 1.0.39 | 137 | 11/8/2025 |
| 1.0.38 | 156 | 11/8/2025 |
| 1.0.37 | 144 | 11/8/2025 |
| 1.0.36 | 202 | 10/12/2025 |
| 1.0.35 | 154 | 10/11/2025 |
| 1.0.34 | 196 | 9/28/2025 |
| 1.0.33 | 210 | 9/2/2025 |
| 1.0.32 | 200 | 9/2/2025 |
| 1.0.31 | 204 | 9/1/2025 |
| 1.0.30 | 200 | 9/1/2025 |
| 1.0.29 | 200 | 9/1/2025 |