Skip to main content

JetStream Deep Dive

JetStream is the part of NATS that stores messages. Once a message is stored, you can read it again later, and replay it as many times as you need. Delivery is tracked per reader: a message counts as handled once it's acknowledged.

This chapter builds that up one page at a time, using a single running example: the Acme ORDERS platform. The same server runs across the whole chapter, and its data carries over from one page to the next.

Who this is for

You've read the Core Concepts → JetStream primer, or you're otherwise comfortable with NATS basics: publishing, subscribing, subjects, and queue groups.

Map

PageWhat you learn
Your first streamWhy a stream, then create the ORDERS stream and read its anatomy
PublishingPublish into a stream and understand the PubAck contract
Reading back the streamRead stored messages back with a durable consumer
Filtering what you consumeAdd a second consumer that reads only orders.shipped
Delivery and acknowledgmentIn-flight, ack, double ack, and redelivery
Acknowledgmentack, nak, term, in-progress, and redelivery timing
Pull consumers in depthfetch vs consume, and the knobs that bound a pull
Scaling a consumerMany workers split the load of one consumer
Ordered consumersA throwaway in-order read of a stream, and the config behind it
Priority groupsSteer which client gets served: overflow and pinned_client
Pausing a consumerStop delivery for a window, then resume
Shaping the streamTune retention limits and discard behavior
Retention policiesLimits, Interest, and WorkQueue retention
Altering stream stateDelete a message or purge the stream, by hand
Surviving node lossReplicas, leaders, and storage durability
Advanced publishingAsync, atomic-batch, and fast-ingest publishing
Mirrors and sourcesCopy one stream, or aggregate many
Reading messages directlyGet one message or a batch straight from the stream, no consumer
Subject mapping and transformsRewrite subjects on the way into a stream, and republish stored messages
Per-message TTLExpire individual messages ahead of the stream
Where to go nextA map of what's beyond this chapter

Prerequisites

You'll need:

  • A running nats-server with JetStream turned on. The simplest way to get one is nats-server -js (see Getting Started).
  • The nats CLI installed and pointed at your server.

Open a terminal and run nats-server -js.