Skip to content

JetStream ​

🚧 In development — JetStream support is actively being implemented. This document covers the core concepts and RobustMQ's support plan.

What is JetStream ​

JetStream is the persistence layer for NATS. It builds on top of Core NATS pub/sub by adding message storage, consumer management, and delivery guarantees. Core NATS is at-most-once — if a message is lost, it's gone. JetStream is at-least-once or exactly-once.

The key difference:

Core NATSJetStream
PersistenceNo — pure in-memoryYes — messages written to a Stream
Delivery semanticsat-most-onceat-least-once / exactly-once
Consumer stateNoneYes (Consumer tracks progress)
Offline messagesLostRetained, replayed on reconnect
ReplayNot supportedSupported (from any offset)
Best forReal-time push, low latencyEvent sourcing, audit logs, reliable delivery

Core Concepts ​

Stream ​

A Stream is JetStream's storage unit. Each Stream binds to a set of subjects — any message published to those subjects is persisted into the Stream.

bash
# Create a Stream binding all messages under orders.>
nats stream add ORDERS \
  --subjects "orders.>" \
  --storage file \
  --retention limits \
  --max-age 24h

Key Stream configuration:

OptionDescription
subjectsBound subjects, wildcards supported
storagefile (persistent) or memory
retentionlimits (by size/age), interest (while consumers exist), workqueue (delete after consume)
max-ageMaximum message retention duration
max-msgsMaximum message count in Stream
max-bytesMaximum bytes in Stream

Consumer ​

A Consumer is a view into a Stream that tracks a subscriber's progress. Each Consumer independently remembers where it left off.

bash
# Create a Push Consumer (server pushes to a subject)
nats consumer add ORDERS payments-service \
  --filter "orders.created" \
  --deliver all \
  --ack explicit

# Create a Pull Consumer (client fetches on demand)
nats consumer add ORDERS audit-log \
  --filter "orders.>" \
  --deliver all \
  --pull

Consumer types:

TypeDescription
Push ConsumerServer pushes messages to a subject — similar to a subscription
Pull ConsumerClient fetches messages on demand — better for batch processing and flow control

Deliver policy (starting position):

OptionDescription
allStart from the oldest message in the Stream
newOnly receive messages published after the Consumer is created
lastStart from the most recent message
by_start_timeStart from a specific timestamp
by_start_sequenceStart from a specific sequence number

ACK Mechanism ​

JetStream requires explicit ACKs from consumers. Unacknowledged messages are redelivered after a timeout.

Ack         # Positive acknowledge — message processed
Nak         # Negative acknowledge — redeliver immediately
InProgress  # Still processing — reset the ACK timeout
Term        # Terminate — do not redeliver

Relationship to Core NATS and mq9 ​

RobustMQ supports three NATS usage modes, each with a distinct purpose:

Core NATSJetStreammq9
PersistenceNoYesYes
Consumer stateNoneYes (offset)None (store-first push)
PriorityNoneNoneThree levels (critical/urgent/normal)
TTLNonePer Stream configPer mailbox config
Best forReal-time push, low latencyEvent streams, audit, reliable deliveryAI Agent async communication
Target usersGeneral pub/subData pipelines, microservicesAI Agents

All three can run on the same RobustMQ instance — choose based on your needs:

  • Extreme low latency, occasional message loss acceptable → Core NATS
  • No message loss, replay support, consumer progress tracking → JetStream
  • AI Agent async communication, offline delivery, priority ordering → mq9

Current Status ​

JetStream is actively being developed. Completed:

  • Stream and Consumer concept design and storage layer mapping
  • Pull Consumer basic functionality

In progress:

  • Push Consumer
  • ACK and redelivery mechanism
  • Exactly-once semantics
  • Stream management API (NATS CLI compatible)

Follow GitHub Milestones for progress updates.

🎉 既然都登录了 GitHub,不如顺手给我们点个 Star 吧!⭐ 你的支持是我们最大的动力 🚀