Giter VIP home page Giter VIP logo

nats.net.v2's Introduction

NATS.NET V2

Preview

The NATS.NET V2 client is in preview and not recommended for production use. Codebase is still under heavy development and currently we only have implementations for core NATS features.

Please test and provide feedback by visiting our Slack channel.

NATS.NET V2 Goals

  • Only support Async I/O
  • Target latest .NET LTS Release (currently net6.0)

Packages

  • NATS.Client.Core: core NATS
  • NATS.Client.Hosting: extension to configure DI container
  • NATS.Client.JetStream: JetStream not yet implemented

Basic Usage

Download the latest nats-server for your platform and run it without any arguments. nats-server will listen on its default TCP port 4222.

Given that we have a plain class Bar, we can publish and subscribe to our nats-server sending and receiving Bar objects:

public record Bar
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Subscribe to all bar related subjects:

await using var nats = new NatsConnection(options);

await using sub = await nats.SubscribeAsync<Bar>("bar.>");
await foreach (var msg in sub.Msgs.ReadAllAsync())
{
    Console.WriteLine($"Received {msg.Subject}: {msg.Data}\n");
}

Publish Bar objects to related bar subjects:

await using var nats = new NatsConnection();

for (int i = 0; i < 10; i++)
{
    Console.WriteLine($" Publishing {i}...");
    await nats.PublishAsync<Bar>($"bar.baz.{i}", new Bar { Id = i, Name = "Baz" });
}

You should also hook your logger to NatsConnection to make sure all is working as expected or to get help diagnosing any issues you might have:

var options = NatsOpts.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
await using var nats = new NatsConnection(options);

Contributing

  • Run dotnet format at root directory of project in order to clear warnings that can be auto-formatted

Attribution

This library is based on the excellent work in Cysharp/AlterNats

nats.net.v2's People

Contributors

neuecc avatar mtmk avatar dalian-spacekey avatar caleblloyd avatar scottf avatar guitarrapc avatar jasper-d avatar bruth avatar to11mtm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.