memory

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package memory is a messaging backend built on channels, depending on nothing.

It earns its place twice: it makes the core module usable and testable with no broker and no dependencies, and it is half of the conformance suite.

It does not validate the abstraction, and that needs saying

An abstraction with one implementation is shaped entirely by that implementation, and nobody finds out until the second arrives. Channels will not find that out, because in-process channels can do everything core NATS can minus the network, so they conform to whatever shape NATS pressed into the interface. The abstraction stays provisional until something genuinely different lands: SQS, which has no fan-out without SNS, or Kafka, with consumer groups and offsets.

Index

Constants

View Source
const DefaultBound = messaging.DefaultQueueBound

DefaultBound is the queue depth a source gets when its spec carries none, which the core never sends: SourceSpec.Bound always arrives with the default applied. Kept as the number this package's own tests reason about. It tracks the core's default rather than restating a number, so the two cannot drift apart.

Variables

View Source
var ErrSessionClosed = errors.NewSentinel("messaging.memory.session_closed",
	"messaging/memory: the session is closed")

ErrSessionClosed is returned by a session that has been closed. A publish arriving after Close must fail promptly rather than appearing to succeed, which is what lets the core bound its shutdown honestly (0002 D11).

View Source
var ErrSourceRetired = errors.NewSentinel("messaging.memory.source_retired",
	"messaging/memory: the source has retired")

ErrSourceRetired is returned when a publish reaches a source that has already retired, which routing allows for an instant after retirement begins.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend is an in-memory messaging.Backend.

It holds nothing but its options: everything a connected lifetime needs belongs to the session it opens, which is what makes sequential sessions structural rather than a rule an implementer has to remember.

func New

func New(opts ...Option) *Backend

New returns a backend.

It acquires nothing that needs releasing, which is the backend contract's one requirement of an implementer.

func (*Backend) Capabilities

func (b *Backend) Capabilities() messaging.Capabilities

Capabilities reports what this backend can honour.

Three overflow policies, because a channel this module owns can implement any of them. That is exactly the asymmetry the contract exists to expose: core NATS can offer only ShedNewest, so a caller moving between the two must ask rather than assume.

func (*Backend) Open

Open returns a new session. Each one is independent, so a bus generation cannot observe its predecessor's sources.

type Option added in v0.6.0

type Option func(*Backend)

Option configures a Backend.

func WithFormat added in v0.6.0

func WithFormat(f envelope.Format) Option

WithFormat carries every event, request and reply through f: written with it on publish, and read back with envelope.Read before any subscriber sees it (spec 0014 D6). A test then sees what that format does to an event, and an event f refuses is refused by Publish, as on a broker.

Without it an event is handed over as published and never encoded, so nothing validates it.

Jump to

Keyboard shortcuts

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