Skip to content

The NATS adapter

Carry the bus over NATS: core NATS when nothing needs to survive, JetStream when it does.

gitlab.com/phpboyscout/go/messaging-nats is the NATS adapter for go/messaging. It is pre-1.0 and tracks the core. This section describes its main branch, and its changelog says which release carries each change. It provides two backends, each a messaging.Backend:

backend := nats.Core(nats.Settings{ /* ... */ })              // volatile, at-most-once
backend := nats.JetStream(nats.JetStreamSettings{ /* ... */ }) // bound to a stream, at-least-once

They are two backends rather than one with a flag because Capabilities.SurvivesRestart is declared, not discovered, and the two answer it differently. See Core NATS or JetStream.

Core JetStream
Delivery modes AtMostOnce AtMostOnce, AtLeastOnce
Survives a restart no yes, on a file-backed stream
Replays from the start of a stream no yes, for a new durable identity
Request and reply yes no

The connection itself, with reconnection, credentials and the draining close, is go/nats's. This adapter writes the consuming, publishing and acknowledging on top of it.

The adapter passes the core's conformance suite: Core under conformance.Run and JetStream under conformance.RunDurable, once for each wire format. See Run the conformance suite.

The design is go/messaging's spec 0003. Where this section and a spec differ, this section describes the code.

Start here

Put a bus on JetStream starts an embedded NATS server, binds a bus to a stream, and watches a declined message come back.

Do a task

Understand it

Look something up