NATS Documentation

repository·master·Indexed 40 days ago

https://github.com/nats-io/nats.docs

A high-performance, lightweight messaging system and data layer for microservices and IoT. Features include Core NATS for best-effort publish-subscribe messaging and JetStream for persistence, guaranteed delivery, and advanced data storage via Key/Value and Object stores. Includes documentation for ecosystem tools such as the nats CLI, nk, nsc, and prometheus-nats-exporter.

Tokens
229K
Snippets
716
Records
1K
Agent score
100%

What's inside NATS

  1. Overview of the nsc tool

    master

    The nsc tool is used to build and manage NATS account configurations. It provides capabilities for managing the lifecycle of NATS security entities and their permissions.

    Key capabilities include:

    • Entity Management: Create and edit Operators, Accounts, and Users.
    • Permissions: Manage publish and subscribe permissions for Users.
    • Exports/Imports: Define Service and Stream exports from an account and reference Service/Streams from other accounts.
    • Access Control: Generate Activation tokens for private services or streams and generate User credential files.
    • Inspection: Describe Operators, Accounts, Users, and Activations.
    • JWT Management: Push and pull account JWTs to/from an account JWTs server.
  2. Overview of NATS security features

    master

    NATS provides a multi-layered security model covering encryption, authentication, authorization, and multi-tenancy:

    • Encryption: Connections can be encrypted using TLS.
    • Authentication: Supports multiple methods including Tokens, Username/Password, TLS Certificates, NKEY with Challenge, and Decentralized JWT.
    • Authorization: Authenticated clients are identified as users with specific permissions (authorizations) to interact with subjects.
    • Multi-tenancy: Use Accounts to create independent subject namespaces. You can control the import/export of messages and services between accounts.
    • Data at Rest: The JetStream persistence layer supports encryption at rest.
  3. Overview of NATS Ecosystem Tools

    master

    The NATS ecosystem provides a variety of specialized tools for managing, monitoring, and benchmarking NATS servers. These tools cover the full lifecycle of NATS operations, including configuration, security, and performance tuning.

    Key tools include:

    • nats CLI: For interacting with and managing NATS servers.
    • nk: For generating NKeys (security credentials).
    • nsc: For configuring Operators, Accounts, and Users.
    • nats account server (nas): For serving Account JWTs.
    • nats top: For real-time monitoring of NATS Server performance.
    • nats-bench: For benchmarking NATS Server performance.
    • prometheus-nats-exporter: For exporting NATS server metrics to Prometheus and visualizing them in Grafana.
  4. Overview of NATS Client Tools

    master

    A NATS client is an application that connects to a NATS server using a connection URL and authenticates via a credential file. While the nats-server does not include clients, several essential tools are available for managing and interacting with NATS infrastructure:

    • nats CLI: The primary tool for testing, monitoring, and managing NATS (local servers, leaf nodes, clusters, or super-clusters).
    • nsc CLI: Used to manage account attributes and user JWT tokens.
    • nk: A tool and library used to manage Nkeys.
    • Client Libraries: Most language-specific client libraries include sample programs for publishing, subscribing, and request-reply patterns.
  5. Overview of NATS capabilities

    master

    NATS is a high-performance data layer designed for cloud-native applications, IoT, and microservices. It provides a single binary with no external dependencies that supports multiple protocols including TCP, MQTT, and WebSockets.

    Core Messaging Features:

    • High-throughput Publish/Subscribe (millions of messages per second) with at-most-once delivery.
    • Fan-in/fan-out delivery patterns.
    • Request/Reply patterns.
    • Support for all major programming languages.

    JetStream Persistence Features:

    • Delivery guarantees: At-least-once or exactly-once delivery.
    • Work queues and stream processing.
    • Data replication, retention, and deduplication.
    • Higher-order data structures: Key/Value (with watchers, versioning, and TTL) and Object Storage (with versioning).

    Infrastructure & Security:

    • Clustering for high availability, fault tolerance, and auto-discovery.
    • Security via TLS and JWT-based zero trust security.
  6. Overview of NATS Command Line Tooling

    master

    The NATS ecosystem provides several tools for interacting with services over NATS/JetStream, managing servers, monitoring, and benchmarking. Key tools include:

    • nats CLI: The primary tool for interacting with, testing, and managing NATS and JetStream from a terminal or scripts. Use the latest version.
    • Security Tools:
      • nk: Generates NKeys for use with JSON Web Tokens (JWT).
      • nsc: The preferred tool for configuring Operators, Accounts, Users, and permissions offline before pushing to production. (Note: Use this instead of the legacy nats account server).
    • Monitoring Tools:
      • nats top: Used to monitor NATS servers.
      • prometheus-nats-exporter: Exports NATS server metrics to Prometheus and Grafana.
    • Benchmarking:
      • nats bench: A subcommand of the nats CLI tool used for performance benchmarking.
  7. Available NATS authentication methods

    master

    The NATS server supports several methods for authenticating clients:

    • Token Authentication: Using a shared token.
    • Plain Text Username/Password: Standard credentials.
    • Bcrypted Username/Password: Securely hashed credentials.
    • TLS Certificate: Using mutual TLS (mTLS) for authentication.
    • NKEY with Challenge: Using NKEY-based asymmetric cryptography.
    • Decentralized JWT Authentication: A decentralized model where account and user information is stored in a resolver rather than the server configuration file.
  8. Key features and deployment capabilities of NATS

    master

    NATS is designed for high mobility and security in modern environments. Key characteristics include:

    • Subject-Based Addressing: NATS manages discovery via subjects rather than hostnames and ports, enabling effortless M:N connectivity.
    • Deployment Flexibility: NATS can be deployed on bare metal, VMs, containers, Kubernetes (K8S), or edge devices.
    • Real-time Topology Updates: NATS infrastructure and clients communicate topology changes in real-time. Clients do not need reconfiguration when backend servers are added or removed; DNS is only used for the initial bootstrap contact.
    • Security: NATS is secure by default and does not rely on network perimeter security models, making it suitable for mobile microservices and edge computing.
    • Hybrid Support: NATS supports hybrid deployments, allowing a mix of shared SaaS/Utility computing and separately owned/operated NATS infrastructure to work together.
  9. Compare NATS with other messaging technologies

    master

    NATS is compared against Apache Kafka, RabbitMQ, Apache Pulsar, and gRPC across several dimensions including patterns, delivery guarantees, and deployment models.

    Key differentiators for NATS include:

    • Built-in Patterns: Supports publish/subscribe, request-reply, and load-balanced queue subscriber patterns natively. Unlike Kafka, Pulsar, or RabbitMQ, NATS does not require application code to manually correlate requests and replies for service patterns.
    • Delivery Guarantees: Provides 'at most once', 'at least once', and 'exactly once' (available in JetStream).
    • Multi-tenancy: Supports true multi-tenancy and decentralized security through the use of accounts and shared streams/services.
    • Deployment Flexibility: NATS is a small static binary capable of running on everything from cloud instances to resource-constrained IoT devices (e.g., Raspberry Pi). It supports an Adaptive Edge architecture including single servers, leaf nodes, clusters, and superclusters (clusters of clusters).
    • Monitoring: Supports exporting data to Prometheus, uses Grafana dashboards, and provides tools like nats-top and NATS surveyor.
  10. Secure NATS connections using TLS, Authentication, and Authorization

    master

    NATS provides a multi-layered security model to protect your messaging infrastructure. To fully secure a NATS deployment, you should implement the following three layers:

    1. Encryption (TLS): Protect data in transit by encrypting connections between clients and servers, or between NATS servers in a cluster, using TLS.
    2. Authentication: Ensure that only known and verified clients can connect to the NATS server.
    3. Authorization: Control what authenticated clients are allowed to do by restricting the specific subjects they can publish to or subscribe from.
  11. Manage JetStream configuration using external tools

    master

    While managing JetStream configuration (such as Streams and Consumers) directly within your application code is a common pattern, you can also pre-create these resources using external automation tools. Supported methods for managing JetStream configuration include:

    • NATS CLI: Using configuration files to define and apply settings.
    • Terraform: Using the NATS provider for Infrastructure as Code (IaC).
    • GitHub Actions: Automating configuration deployment via CI/CD.
    • Kubernetes JetStream Controller: Managing JetStream resources natively within a Kubernetes cluster.