Skip to content

About

The messaging infrastructure library of Go Elemental

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

241 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-messaging

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.

Modules

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.

Packages

  • messaging (the root) is the broker contract and the runtime: Broker and Publisher, Subscription and its Start, the delivery Attempt, the source's Report, Config, the Runtime with its Relay and Consume reactors, the Setup whose Build builds it, the error hook's Failure and Hook, and the quiesce gate's Gate. Its Journal, with Entry and ErrConflict, appends to a subject of the broker's stream, reads the subject back, and follows it as its events are stored, through Follow and its FollowOptions. Its History, with ScanOptions and ErrNotFound, scans the stream across subjects, follows it across subjects as its events are stored, through FollowStream and its StreamFollowOptions, gets one event by its stream sequence, and reports the stream's creation time and last sequence, through Info and its StreamInfo. ErrStreamReplaced ends either follow when its stream is deleted or recreated. Its Queue, with Worker and DeadLetter, holds durable jobs apart from the broker's stream until one worker of a group acknowledges each or the queue dead-letters it, and Runtime.Work builds the reactor that runs a worker group's jobs.
  • outbox writes 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.Relay takes its report, per-row timeout, last-pass drain, and gate as one outbox.RelayOptions value.
  • inbox is a consumer's claim on an event, so a redelivery is handled once.
  • memory is the in-memory provider, a Broker that is also a Journal and a History, and a Queue beside them, for a service's tests and the conformance double. Broker.Recreate replaces its log with an empty one, as if its stream were recreated, for a test or a development reset.
  • messagingtest is the conformance suite every provider passes: Run for the broker, RunJournal for the journal, RunHistory for the history, and RunQueue for the work queue.
  • postgres (sub-module) is the PostgreSQL engine: the outbox's and inbox's statements, the messaging migration set, Verify, Pending, and the retentions, OutboxRetention and InboxRetention, that delete aged published and handled rows a budget at a time.
  • nats (sub-module) is the NATS JetStream provider. Its Broker runs on one stream, with a Config block that holds the stream's owner switch, and its sources bind durable pull consumers. The Broker is also a Journal, which reads a subject through an ordered consumer and follows it through an ephemeral one, and a History, 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's StreamInfo from the server. Its Queue runs on a stream of its own with work-queue retention, configured by its QueueConfig block. Its natstest package 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.

Usage

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.

Development

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 data

mise 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.

Releases

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.

License

Apache License 2.0.

About

The messaging infrastructure library of Go Elemental

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages