Help us shape the future of Go! Take the 2026 Go Developer Survey

bus

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package bus is the messaging port (ADR-0008): core pub/sub plus durable JetStream streams/consumers, behind the bus.Bus port. It is the internal-plane messaging substrate — never handed to functions (the raw JetStream API is not exposed beyond this port; blueprint security note).

This package imports no nats library; the embedded-NATS driver (memory / file storage, pure-Go) lives in internal/bus/nats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	Publish(ctx context.Context, subject Subject, data []byte) error
	Subscribe(ctx context.Context, subject Subject) (Subscription, error)
	EnsureStream(ctx context.Context, cfg StreamConfig) error
	Consume(ctx context.Context, cfg ConsumeConfig) (Consumer, error)
	Close() error
}

Bus is the messaging port: core pub/sub plus durable JetStream streams/consumers. Errors are api/fault kinds; every method is ctx-first. The port imports no nats library.

type ConsumeConfig

type ConsumeConfig struct {
	Stream  string
	Durable string
	Subject Subject
}

ConsumeConfig declares a durable consumer on a stream for a subject filter.

type Consumer

type Consumer interface {
	C() <-chan Message
	Close() error
}

Consumer is a durable JetStream consumer. Close releases it (the stream persists) and stops the delivery goroutine (no leak); C() is closed on Close.

type Message

type Message struct {
	Subject Subject
	Data    []byte
	// contains filtered or unexported fields
}

Message is one delivered message. Ack acknowledges a durable (JetStream) message; for a core Subscription it is a no-op. Drivers construct it via NewMessage.

func NewMessage

func NewMessage(subject Subject, data []byte, ack func() error) Message

NewMessage builds a Message — the driver-facing constructor (the ack closure is unexported, so a driver in another package sets it through here).

func (Message) Ack

func (m Message) Ack() error

Ack acknowledges a durable message; a nil ack (core pub/sub) is a no-op.

type StreamConfig

type StreamConfig struct {
	Name     string
	Subjects []Subject
	MaxAge   time.Duration
}

StreamConfig declares a durable JetStream stream capturing the given subjects. MaxAge bounds how long the stream keeps a message; zero sets no age limit.

type Subject

type Subject string

Subject is a typed NATS subject (dot-delimited; namespaced as ns.<namespace>.…).

type Subscription

type Subscription interface {
	C() <-chan Message
	Unsubscribe() error
}

Subscription is an ephemeral core subscription. Unsubscribe releases it and stops the delivery goroutine (no leak); C() is closed on Unsubscribe.

Directories

Path Synopsis
Package buscontract is the shared conformance suite for the bus.Bus port (ADR-0008).
Package buscontract is the shared conformance suite for the bus.Bus port (ADR-0008).
Package nats is the embedded-NATS driver for the bus.Bus port (ADR-0008): an in-process nats-server with JetStream (memory or file storage), all pure-Go (no cgo).
Package nats is the embedded-NATS driver for the bus.Bus port (ADR-0008): an in-process nats-server with JetStream (memory or file storage), all pure-Go (no cgo).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL