Available

amalgame-nats

NATS Core client over raw TCP, no external library.

amc package add nats GitHub ↗ ← Back to the ecosystem

Overview

NATS Core client written directly on the text protocol (CONNECT, PUB, SUB, MSG, PING). No vendored C library. It works with nats-server, without TLS or authentication.

Features

  • ✓Pure-text NATS Core protocol
  • ✓Pub/sub with subjects and wildcards (* / >), one active subscription per connection
  • ✓Request/reply pattern (RPC-style)
  • ✓Queue groups — load balancing across subscribers

Planned for v3: TLS, authentication, several subscriptions per connection.

Example

Minimal usage example — copy-paste runnable after install.

amc package add nats

import Amalgame.Messaging.NATS

public class Program {
    public static void Main(string[] args) {
        let n = NATS.Open("localhost", 4222)
        if (!NATS.IsOpen(n)) {
            Console.WriteLine("connect failed: " + NATS.LastError(n))
            return
        }
        NATS.Subscribe(n, "orders.*")
        NATS.Publish(n, "orders.new", "id=42")
        if (NATS.WaitMessage(n, 5000)) {
            Console.WriteLine(NATS.LastSubject(n) + ": " + NATS.LastPayload(n))
        }
        let reply: string = NATS.Request(n, "service.echo", "ping", 2000)
        Console.WriteLine("reply: " + reply)
        NATS.Close(n)
    }
}

At a glance

Related packages