Skip to content

NATS Jetstream updates #5107

@joeblew999

Description

@joeblew999

Summary

Request to add NATS JetStream as a message queue backend alongside the existing Kafka
support in go-queue, enabling go-zero applications to leverage NATS for messaging
infrastructure.

Problem Statement

Currently, go-zero only supports Kafka through go-queue for message queuing. However,
many organizations prefer NATS for its:

  • Lightweight footprint - single binary deployment
  • Embedded capability - can run in-process with applications
  • Clustering support - automatic failover and data replication
  • Network partition resilience - local operation with automatic sync when connectivity
    returns
  • Pure Go implementation - no external dependencies

Proposed Solution

Add NATS JetStream support to go-queue with similar API patterns to the existing Kafka
(kq) implementation:

  // Proposed API structure
  type NatsConfig struct {
      Servers      []string
      StreamName   string
      Subject      string
      ConsumerName string
      // ... other NATS-specific options
  }

  // Producer
  func NewNatsProducer(config NatsConfig) *NatsProducer

  // Consumer  
  func NewNatsConsumer(config NatsConfig) *NatsConsumer

Benefits

  1. Deployment flexibility - embed NATS in single-node deployments or use clustered
    setup
  2. Operational resilience - applications continue working during network partitions
  3. Resource efficiency - lower memory and CPU footprint than Kafka
  4. Developer experience - native Go implementation, easier debugging and deployment

Implementation Approach

  • Follow existing go-queue patterns (kq structure)
  • Leverage https://github.com/nats-io/nats.go client library
  • Support both core NATS and JetStream features
  • Maintain API consistency with existing kq implementation

Use Cases

  • Edge computing - applications that need messaging without external infrastructure
  • Development environments - simplified local development with embedded messaging
  • Hybrid deployments - gradual migration from single-node to clustered setups
  • Network-constrained environments - applications that must operate during
    connectivity issues

Offer to Contribute

I'm willing to contribute to this implementation and can provide:

  • Initial proof-of-concept
  • Test cases and documentation
  • Real-world testing feedback

This would significantly expand go-zero's messaging capabilities and provide
developers with more deployment options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions