Convert Figma logo to code with AI

nats-io logonats-streaming-server

NATS Streaming System Server

2,509
283
2,509
59

Top Related Projects

High-Performance server for NATS.io, the cloud and edge native messaging system.

14,185

Apache Pulsar - distributed pub-sub messaging system

28,601

Mirror of Apache Kafka

Open source RabbitMQ: core server and tier 1 (built-in) plugins

21,052

Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.

13,968

The most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles

Quick Overview

NATS Streaming Server is a data streaming system powered by NATS, providing features like message persistence, at-least-once delivery, and durable subscriptions. It's designed for high-throughput, low-latency messaging in distributed systems, making it suitable for event-driven architectures and microservices.

Pros

  • High performance and low latency messaging
  • Supports durable subscriptions and message persistence
  • Easy to set up and integrate with existing NATS infrastructure
  • Provides at-least-once delivery semantics

Cons

  • Limited scalability compared to some other streaming solutions
  • Lacks some advanced features found in more complex streaming platforms
  • Requires careful configuration for optimal performance in large-scale deployments
  • Limited built-in monitoring and observability tools

Getting Started

To get started with NATS Streaming Server:

  1. Install the server:

    go install github.com/nats-io/nats-streaming-server@latest
    
  2. Start the server:

    nats-streaming-server
    
  3. Install the Go client:

    go get github.com/nats-io/stan.go
    
  4. Use the following code to publish and subscribe to messages:

package main

import (
    "log"
    "github.com/nats-io/stan.go"
)

func main() {
    // Connect to NATS Streaming
    sc, err := stan.Connect("test-cluster", "client-1")
    if err != nil {
        log.Fatal(err)
    }
    defer sc.Close()

    // Publish a message
    err = sc.Publish("foo", []byte("Hello World"))
    if err != nil {
        log.Fatal(err)
    }

    // Subscribe to messages
    sub, err := sc.Subscribe("foo", func(m *stan.Msg) {
        log.Printf("Received a message: %s\n", string(m.Data))
    })
    if err != nil {
        log.Fatal(err)
    }
    defer sub.Unsubscribe()

    // Keep the connection alive
    select {}
}

This example demonstrates how to connect to NATS Streaming, publish a message, and subscribe to receive messages on a specific subject.

Competitor Comparisons

High-Performance server for NATS.io, the cloud and edge native messaging system.

Pros of nats-server

  • Lightweight and high-performance, optimized for low-latency messaging
  • Supports clustering and fault tolerance out of the box
  • Simpler architecture, easier to set up and maintain

Cons of nats-server

  • Limited persistence capabilities compared to nats-streaming-server
  • Lacks advanced features like message replay and durable subscriptions

Code Comparison

nats-server:

nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
    log.Fatal(err)
}
defer nc.Close()

nats-streaming-server:

sc, err := stan.Connect(clusterID, clientID, stan.NatsURL(nats.DefaultURL))
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

The main difference in usage is that nats-streaming-server requires additional parameters (clusterID and clientID) for connection, reflecting its more advanced features and persistence capabilities. nats-server, being simpler, only needs the NATS URL for connection.

Both projects serve different use cases: nats-server is ideal for high-throughput, low-latency messaging scenarios, while nats-streaming-server is better suited for applications requiring message persistence, replay, and durable subscriptions. The choice between them depends on the specific requirements of your messaging system.

14,185

Apache Pulsar - distributed pub-sub messaging system

Pros of Pulsar

  • Multi-tenancy support with built-in isolation and resource management
  • Tiered storage for cost-effective data retention and scalability
  • Unified streaming and queuing model with support for both pub-sub and queue semantics

Cons of Pulsar

  • More complex setup and configuration compared to NATS Streaming Server
  • Higher resource requirements for deployment and operation
  • Steeper learning curve due to its extensive feature set

Code Comparison

NATS Streaming Server (Go):

sc, _ := stan.Connect(clusterID, clientID)
sub, _ := sc.Subscribe("foo", func(m *stan.Msg) {
    fmt.Printf("Received a message: %s\n", string(m.Data))
})

Pulsar (Java):

PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
Consumer<byte[]> consumer = client.newConsumer().topic("my-topic").subscribe();
Message msg = consumer.receive();
System.out.println("Received message: " + new String(msg.getData()));

Both NATS Streaming Server and Pulsar are messaging systems, but Pulsar offers more advanced features for large-scale deployments. NATS Streaming Server is simpler and easier to set up, making it suitable for smaller projects or those requiring a lightweight solution. Pulsar excels in scenarios demanding high scalability, multi-tenancy, and advanced data retention capabilities.

28,601

Mirror of Apache Kafka

Pros of Kafka

  • Highly scalable and distributed architecture, capable of handling massive data streams
  • Strong support for data retention and replay, allowing for complex event processing
  • Rich ecosystem with numerous connectors and integrations

Cons of Kafka

  • More complex setup and configuration compared to NATS Streaming Server
  • Higher resource consumption, especially for smaller deployments
  • Steeper learning curve for developers and operators

Code Comparison

NATS Streaming Server (Go):

sc, _ := stan.Connect(clusterID, clientID)
sc.Publish("foo", []byte("Hello World"))

Kafka (Java):

Producer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("topic", "Hello World"));

Key Differences

  • NATS Streaming Server is lightweight and easy to set up, while Kafka offers more robust features for large-scale deployments
  • Kafka provides stronger guarantees for message ordering and delivery, but at the cost of increased complexity
  • NATS Streaming Server uses a simpler pub-sub model, whereas Kafka employs a log-based approach with partitions and consumer groups

Both systems have their strengths, and the choice between them depends on specific use cases and requirements. NATS Streaming Server is often preferred for simpler, lightweight messaging needs, while Kafka is chosen for large-scale, distributed data streaming applications.

Open source RabbitMQ: core server and tier 1 (built-in) plugins

Pros of RabbitMQ Server

  • More mature and feature-rich, with extensive plugin ecosystem
  • Supports multiple protocols (AMQP, MQTT, STOMP)
  • Better suited for complex routing scenarios and message patterns

Cons of RabbitMQ Server

  • Higher resource consumption and slower performance under heavy loads
  • More complex setup and configuration process
  • Steeper learning curve for beginners

Code Comparison

NATS Streaming Server (Go):

nc, _ := nats.Connect(nats.DefaultURL)
sc, _ := stan.Connect("cluster-id", "client-id", stan.NatsConn(nc))
sc.Publish("foo", []byte("Hello World"))

RabbitMQ Server (Erlang):

{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
{ok, Channel} = amqp_connection:open_channel(Connection),
Publish = #'basic.publish'{exchange = <<"">>, routing_key = <<"hello">>},
amqp_channel:cast(Channel, Publish, #amqp_msg{payload = <<"Hello World!">>})

Both NATS Streaming Server and RabbitMQ Server are popular message brokers, but they cater to different use cases. NATS Streaming Server is lightweight and focuses on high-performance messaging, while RabbitMQ Server offers more advanced features and flexibility at the cost of increased complexity and resource usage. The choice between the two depends on specific project requirements and scalability needs.

21,052

Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.

Pros of RocketMQ

  • Supports multiple messaging patterns (pub/sub, P2P, broadcasting)
  • Offers built-in message tracing and metrics
  • Provides strong consistency and high availability through master-slave architecture

Cons of RocketMQ

  • More complex setup and configuration compared to NATS Streaming Server
  • Higher resource consumption, especially for large-scale deployments
  • Steeper learning curve for developers new to message queue systems

Code Comparison

NATS Streaming Server (Go):

sc, _ := stan.Connect(clusterID, clientID)
sub, _ := sc.Subscribe("foo", func(m *stan.Msg) {
    fmt.Printf("Received a message: %s\n", string(m.Data))
})

RocketMQ (Java):

DefaultMQProducer producer = new DefaultMQProducer("ProducerGroup");
producer.setNamesrvAddr("localhost:9876");
producer.start();
Message msg = new Message("TopicTest", "TagA", "Hello RocketMQ".getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.send(msg);

Both systems offer reliable message queuing, but RocketMQ provides more advanced features at the cost of increased complexity. NATS Streaming Server is simpler to set up and use, making it a good choice for smaller projects or those requiring low-latency messaging. RocketMQ is better suited for large-scale, enterprise-level applications that need advanced messaging patterns and strong consistency guarantees.

13,968

The most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles

Pros of EMQX

  • Highly scalable, supporting millions of concurrent MQTT connections
  • Rich feature set including rule engine, data bridging, and multi-protocol support
  • Extensive plugin system for customization and extension

Cons of EMQX

  • Steeper learning curve due to more complex architecture
  • Higher resource consumption compared to NATS Streaming Server
  • Less focus on persistence and message replay capabilities

Code Comparison

EMQX configuration (emqx.conf):

node.name = emqx@127.0.0.1
node.cookie = emqxsecretcookie
cluster.name = emqxcl
listener.tcp.external = 0.0.0.0:1883

NATS Streaming Server configuration (server.conf):

port: 4222
http_port: 8222
cluster {
  port: 6222
  routes: ["nats://localhost:6222"]
}

EMQX offers a more comprehensive MQTT-focused solution with advanced features, while NATS Streaming Server provides a simpler, lightweight option for general pub/sub messaging. EMQX excels in large-scale IoT scenarios, whereas NATS Streaming Server is better suited for simpler messaging needs with strong persistence requirements. The choice between them depends on specific project requirements, scalability needs, and the desired level of feature complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NATS Streaming Server

NATS Streaming is an extremely performant, lightweight reliable streaming platform built on NATS.

License ReportCard Build Release Coverage

WARNING: Deprecation Notice :warning:

The NATS Streaming Server is being deprecated. Critical bug fixes and security fixes will be applied until June of 2023. NATS enabled applications requiring persistence should use JetStream.

Documentation

Clients

You can find here the list of NATS Streaming clients supported by Synadia. There are also links to community-contributed clients.

Contact

  • Twitter: Follow us on Twitter!
  • Google Groups: Where you can ask questions
  • Slack: To join go here. You can ask questions to our maintainers and to the rich and active community.

Contributing

If you are interested in contributing to NATS, read about our...

Security

If you've found a vulnerability or a potential vulnerability in the NATS server, please let us know at nats-security.

License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.