cloops.nats 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package cloops.nats --version 1.1.2
                    
NuGet\Install-Package cloops.nats -Version 1.1.2
                    
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.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="cloops.nats" Version="1.1.2" />
                    
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.2
                    
#r "nuget: cloops.nats, 1.1.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=cloops.nats&version=1.1.2
                    
Install as a Cake Tool

CLOOPS NATS SDK

the words events are messages are same and are used Interchangeably.

This SDK enables you to build reliable distributed systems using NATS messaging system. It enables annotation based definitions to control behavior of your NATS subscribers.

Overview

Using NATS as communication layer for your distributed systems is quite impressive. You can implement sophisticated load balancing, fault tolerant systems that are location transparent and globally distributed.

  • Leaner than http - It's a binary protocol
  • Less number of hops - No load balancers, API gateways etc.
  • Globally distributed - You can distribute your applications across the globe without any kind of DNS and load balancing complexity. Check out NATS super cluster for additional details

Check out this podcast from nats.fm for additional insights into this.

However, developers now a days expect annotation based definitions and dependency injection setups that are common across virtually any modern REST framework. With this project we are trying to supply similar framework to provide the same developer experience to teams that want to build their applications using NATS. Our hope is that this will reduce other differentiated work of consumer behavior handling.

This framework helps you with -

  • Defining your NATS subscribers with annotations
  • Provide back pressure in case of spikes
  • Control load balancing strategies (i.e. broadcasting, load balancing)
  • Works JetStream for building temporally decoupled systems.

If you are building microservices then, we have a microservices focused SDK with all the bells and whistles built on top of cloops.nats. It is free and open source. Please check it out here

Quick Examples

Broadcast with unique pod names (for Kubernetes/Docker)

To ensure each pod/instance receives all messages (broadcast), use runtime placeholders in the queue group name:

/// <summary>
/// Broadcast scenario: Each pod gets a unique queue group name, 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")}] message received: {msg.Data}");
    return Task.FromResult(new NatsAck(true));
}

The SDK resolves placeholders at runtime:

  • {POD_NAME} - resolves to POD_NAME env var, or HOSTNAME, or machine name
  • {HOSTNAME} - resolves to HOSTNAME env var, or machine name
  • {MACHINE_NAME} - resolves to machine name
  • {ENV:VAR_NAME} - resolves to any environment variable (e.g., {ENV:MY_CUSTOM_VAR})

Load balancing example

Use same QueueGroup Name for multiple instances

[NatsConsumer("test.lb", _QueueGroupName: "workers")]
public async Task<NatsAck> HandleQueueGroup1(NatsMsg<string> msg, CancellationToken ct = default)
{
    Console.WriteLine($"LB - instance 1] message received: {msg.Data}");
    await Task.Delay(100, ct).ConfigureAwait(false); // Simulate work
    return new NatsAck(true);
}

Note: _QueueGroupName is optional, and if you do not provide one the empty string is used. It still makes consumers load balanced

Note: JetStream subscriptions in cloops.nats are load balanced always (i.e. no broadcast)

Installation

Add cloops.nats package reference to your .csproj file. Please note we deliberately want all of our consumers to stay on latest version of the SDK.

<PackageReference Include="cloops.nats" Version="*" />

Once added, just to dotnet restore to pull in the SDK.

Please note: to get our Connection Loops standard messages, subjects etc., you might need to pull in cloops.nats.schema

Quickstarts

Take a look at some examples here

Documentation

For detailed documentation, setup instructions, and contribution guidelines:

📚 View Complete Documentation

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 5,865 12/14/2025
1.1.5 199 12/14/2025
1.1.4 198 12/14/2025
1.1.3 155 12/14/2025
1.1.2 149 12/14/2025
1.1.1 159 12/13/2025
1.0.42 358 11/17/2025
1.0.41 271 11/9/2025
1.0.40 201 11/9/2025
1.0.39 153 11/8/2025
1.0.38 172 11/8/2025
1.0.37 168 11/8/2025
1.0.36 215 10/12/2025
1.0.35 169 10/11/2025
1.0.34 214 9/28/2025
1.0.33 224 9/2/2025
1.0.32 220 9/2/2025
1.0.31 220 9/1/2025
1.0.30 216 9/1/2025
1.0.29 219 9/1/2025
Loading failed