The messaging infrastructure library of Go Elemental: one broker-agnostic contract for a service
to emit events and run reactors on. Events are go-core's CloudEvents event type, emitted through
a transactional outbox and consumed idempotently through an inbox, and every consumer is a go-core
reactor on a subscription source.
| Module | Import path | Tags |
|---|---|---|
| Base | github.com/standards-lab/go-messaging |
v* |
| PostgreSQL engine | github.com/standards-lab/go-messaging/postgres |
postgres/v* |
| NATS JetStream provider | github.com/standards-lab/go-messaging/nats |
nats/v* |
The base module depends on the standard library, go-core, and sqlate with its query package,
the adjacent library the outbox's and inbox's engine contract builds on, and nothing else: no
driver, no dialect, no broker client. depguard holds the base to that line in mise run check. An
engine's driver and dialect enter only through its sub-module, and a broker's client only through
its provider's.
messaging(the root) is the broker contract and the runtime:BrokerandPublisher,Subscriptionand itsStart, the deliveryAttempt, the source'sReport,Config, theRuntimewith itsRelayandConsumereactors, theSetupwhoseBuildbuilds it, the error hook'sFailureandHook, and the quiesce gate'sGate. ItsJournal, withEntryandErrConflict, appends to a subject of the broker's stream, reads the subject back, and follows it as its events are stored, throughFollowand itsFollowOptions. ItsHistory, withScanOptionsandErrNotFound, scans the stream across subjects, follows it across subjects as its events are stored, throughFollowStreamand itsStreamFollowOptions, gets one event by its stream sequence, and reports the stream's creation time and last sequence, throughInfoand itsStreamInfo.ErrStreamReplacedends either follow when its stream is deleted or recreated. ItsQueue, withWorkerandDeadLetter, holds durable jobs apart from the broker's stream until one worker of a group acknowledges each or the queue dead-letters it, andRuntime.Workbuilds the reactor that runs a worker group's jobs.outboxwrites a command's events in the command's own transaction and relays them to the broker, quarantining a row that can never be published.Outbox.Relaytakes its report, per-row timeout, last-pass drain, and gate as oneoutbox.RelayOptionsvalue.inboxis a consumer's claim on an event, so a redelivery is handled once.memoryis the in-memory provider, aBrokerthat is also aJournaland aHistory, and aQueuebeside them, for a service's tests and the conformance double.Broker.Recreatereplaces its log with an empty one, as if its stream were recreated, for a test or a development reset.messagingtestis the conformance suite every provider passes:Runfor the broker,RunJournalfor the journal,RunHistoryfor the history, andRunQueuefor the work queue.postgres(sub-module) is the PostgreSQL engine: the outbox's and inbox's statements, themessagingmigration set,Verify,Pending, and the retentions,OutboxRetentionandInboxRetention, that delete aged published and handled rows a budget at a time.nats(sub-module) is the NATS JetStream provider. ItsBrokerruns on one stream, with aConfigblock that holds the stream's owner switch, and its sources bind durable pull consumers. TheBrokeris also aJournal, which reads a subject through an ordered consumer and follows it through an ephemeral one, and aHistory, which scans the stream through an ordered consumer and follows it through an ephemeral one, gets an event by its sequence, and reports the stream'sStreamInfofrom the server. ItsQueueruns on a stream of its own with work-queue retention, configured by itsQueueConfigblock. Itsnatstestpackage gives each test its own stream.
The package documentation, go doc github.com/standards-lab/go-messaging/..., is the reference
for each exported name; each package's doc.go inventories its exports.
docs/usage.md shows the library in use: wiring the runtime, the NATS broker,
the relay and consumers as graph nodes, the error hook, quarantine, retention, MaxDeliver
exhaustion, the quiesce gate, folding and appending to a stream-backed root, and the work queue.
The repository is a Go workspace of three modules, ., postgres, and nats. Tasks run through
mise:
mise run check # build, vet, format, fix, tidy, test, and lint every module, then sqlint, lint-context, and lint-references; writes nothing
mise run integration:postgres # the postgres module's integration suite against a fresh compose PostgreSQL
mise run integration:nats # the nats module's integration suite against a fresh compose NATS
mise run integration # both suites, each against its own fresh service
mise run currency # report tools, Go, requirements, action pins, image tags, and Dockerfile pins behind their latest, a held one with its reason; writes nothing
mise run upgrade # move every trailing pin but a held one to its latest
mise run fmt # format all Go source
mise run tidy # run go mod tidy in every module
mise run up # start every compose service and wait until each is healthy
mise run down # stop them, discarding their datamise run check runs the step scripts in scripts/check/: go.sh, the Go gates in each module
with the workspace off, so each resolves its own pins; then sqlint.sh; then lints.sh. Where
MISE_ENV=agent is set, as .claude/settings.json sets it for the agent, mise also loads the agent
profile, mise.agent.toml, which adds the tasks in .agent/mise-tasks/: check:go,
check:sqlint, and check:lints, one per step, and test, vet, and lint, one gate each.
mise.toml's HOLDS lists the held pins.
compose.yml runs PostgreSQL on port 5435 and NATS with JetStream on port 4225, clear of the other
repositories' development ports. POSTGRES_PORT and NATS_PORT move them, and MESSAGING_DSN and
MESSAGING_NATS_URL in mise.toml follow. Each integration task starts only its own service and
stops it whatever the result. Both services keep their data in tmpfs; the postgres suite gives each
test its own database, and the nats suite its own stream. CI runs the check on every pull request
and push to main, and both integration suites on push to main and on manual dispatch.
docs/internals.md holds the reasoning behind the unexported machinery of
each package, for a contributor changing it.
Each module is versioned and released on its own tags: v* for the base module, postgres/v*
for the engine, and nats/v* for the provider. A pushed tag creates the module's GitHub release
from the matching section of its changelog: CHANGELOG.md,
postgres/CHANGELOG.md, and nats/CHANGELOG.md.