cloops.nats.schema 1.0.6

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package cloops.nats.schema --version 1.0.6
                    
NuGet\Install-Package cloops.nats.schema -Version 1.0.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.schema" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="cloops.nats.schema" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="cloops.nats.schema" />
                    
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.schema --version 1.0.6
                    
#r "nuget: cloops.nats.schema, 1.0.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.schema@1.0.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.schema&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=cloops.nats.schema&version=1.0.6
                    
Install as a Cake Tool

CLOOPS Nats Schema

The official Connection Loops SDK for defining strongly typed schemas across all the microservices in Connection Loops.

🚀 Overview

The goal here is to have strong types for every single message passed between any two microservices in Connection Loops.

This repo makes our cloops.nats SDK generic to handle NATS connection logic and this repo defines all the messages.

The aim here is to reduce potential errors due to loose types and weak contracts

⚡ Benefits of having strong types for nats

  • Less chance of surprise failures.
  • Better developer experience
  • Lock down a subject with a specific message
  • Automatic input validation before publishing/requesting

📋 Subject Types

This SDK supports three types of NATS subjects, each serving a specific communication pattern:

P_Subject - Publish Subject

  • Purpose: Core NATS publishing for fire-and-forget messaging
  • Use Case: When you need to broadcast events without expecting a response
  • Example: Publishing events, notifications, or logging messages
  • Method: Publish(T payload) - validates and publishes the message

S_Subject - Stream Subject (JetStream)

  • Purpose: JetStream publishing for durable, persistent messaging
  • Use Case: When you need message persistence, delivery tracking, and guaranteed delivery
  • Features: Supports deduplication, message acknowledgment, and stream-based delivery
  • Method: StreamPublish(T payload, ...) - validates and publishes with JetStream guarantees

R_Subject - Request-Reply Subject

  • Purpose: Request-response pattern for synchronous communication
  • Use Case: When you need to send a request and wait for a specific reply
  • Pattern: Request-reply is only applicable in core NATS (not JetStream)
  • Method: Request(Q payload) - validates the request and returns the reply

Note: All subject names should start with their type prefix (P, S, or R) when defined in subject builders.

🧩 Installation

This SDK is part of cloops.microservices. It is recommended that you bring in the whole package that cloops.microservices offers.

🔄 Existing Projects

Add cloops.nats.schema 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.schema" Version="*" />

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

📝 Message Validation

All messages in this SDK inherit from BaseMessage and support automatic validation using Data Annotations. Validation is automatically performed when you publish or send messages through subjects.

How It Works

  1. Inherit from BaseMessage: All message classes inherit from BaseMessage
  2. Add Validation Attributes: Use Data Annotations attributes like [Required], [Range], [Url], etc.
  3. Automatic Validation: Validation is triggered automatically when you call:
    • P_Subject.Publish() - validates before publishing
    • S_Subject.StreamPublish() - validates before stream publishing
    • R_Subject.Request() - validates the request before sending

Example

public class MyMessage : BaseMessage
{
    [Required(ErrorMessage = "Id is required")]
    public string Id { get; set; }

    [Range(1, 100, ErrorMessage = "Value must be between 1 and 100")]
    public int Value { get; set; }

    [Url(ErrorMessage = "Url must be a valid URL")]
    public string Url { get; set; }
}

// Usage - validation happens automatically
var message = new MyMessage { Id = "123", Value = 50, Url = "https://example.com" };
await subject.Publish(message); // Validates and publishes, throws ValidationException if invalid

If validation fails, a ValidationException is thrown with details about what failed.

🤝 Contribution Guidelines

Please see our Contribution Guidelines for detailed information on how to contribute to this SDK, including:

  • Subject and message type conventions
  • Validation requirements
  • Testing requirements
  • Best practices for compiler-level validation
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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated