cloops.nats 1.1.6

dotnet add package cloops.nats --version 1.1.6
                    
NuGet\Install-Package cloops.nats -Version 1.1.6
                    
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="cloops.nats" Version="1.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="cloops.nats" Version="1.1.6" />
                    
Directory.Packages.props
<PackageReference Include="cloops.nats" />
                    
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 cloops.nats --version 1.1.6
                    
#r "nuget: cloops.nats, 1.1.6"
                    
#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 cloops.nats@1.1.6
                    
#: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=cloops.nats&version=1.1.6
                    
Install as a Cake Addin
#tool nuget:?package=cloops.nats&version=1.1.6
                    
Install as a Cake Tool

CLOOPS NATS SDK

CI NuGet License: MIT

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.nats and 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_NAME env var, falls back to HOSTNAME or machine name
  • {HOSTNAME} β†’ HOSTNAME env var, falls back to machine name
  • {MACHINE_NAME} β†’ Machine name
  • {ENV:VAR_NAME} β†’ Any environment variable (e.g., {ENV:MY_CUSTOM_VAR})

πŸ“ Note: QueueGroupName is 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed