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
| Page | What you learn |
|---|---|
| Your first stream | Why a stream, then create the ORDERS stream and read its anatomy |
| Publishing | Publish into a stream and understand the PubAck contract |
| Reading back the stream | Read stored messages back with a durable consumer |
| Filtering what you consume | Add a second consumer that reads only orders.shipped |
| Delivery and acknowledgment | In-flight, ack, double ack, and redelivery |
| Acknowledgment | ack, nak, term, in-progress, and redelivery timing |
| Pull consumers in depth | fetch vs consume, and the knobs that bound a pull |
| Scaling a consumer | Many workers split the load of one consumer |
| Ordered consumers | A throwaway in-order read of a stream, and the config behind it |
| Priority groups | Steer which client gets served: overflow and pinned_client |
| Pausing a consumer | Stop delivery for a window, then resume |
| Shaping the stream | Tune retention limits and discard behavior |
| Retention policies | Limits, Interest, and WorkQueue retention |
| Altering stream state | Delete a message or purge the stream, by hand |
| Surviving node loss | Replicas, leaders, and storage durability |
| Advanced publishing | Async, atomic-batch, and fast-ingest publishing |
| Mirrors and sources | Copy one stream, or aggregate many |
| Reading messages directly | Get one message or a batch straight from the stream, no consumer |
| Subject mapping and transforms | Rewrite subjects on the way into a stream, and republish stored messages |
| Per-message TTL | Expire individual messages ahead of the stream |
| Where to go next | A map of what's beyond this chapter |
Prerequisites
You'll need:
- A running
nats-serverwith JetStream turned on. The simplest way to get one isnats-server -js(see Getting Started). - The
natsCLI installed and pointed at your server.
Open a terminal and run nats-server -js.