memory

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package memory is the in-memory messaging provider: the conformance double for the standard tier and a test double for a service.

The package exports:

A Broker keeps one append-only log of encoded events, as a JetStream stream would, and a durable consumer for each subscription Name that starts at the log's beginning, or at its end under messaging.StartNew, once Subscribe creates it. Publish encodes an event to binary content mode and each delivery decodes it, so the codec a real binding uses is exercised on every message; one that fails to decode is passed to the subscription's report and terminated. Each delivery's context carries its attempt, the event's delivery count. Like a stream with a deduplication window, the broker drops a publish of a source and id it has seen within messaging.DefaultDuplicates. Nothing persists beyond the process.

The package reads in three layers: broker.go holds the log and the consumers, consumer.go is each consumer's delivery state machine, and source.go is the member loop a reactor runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker is an in-memory messaging.Broker. Its zero value is not usable; call New.

One mutex guards the log and every consumer, so the consumer's methods never lock; the broker and the sources take mu around them.

func New

func New() *Broker

New returns an empty broker.

func (*Broker) Publish

func (b *Broker) Publish(_ context.Context, e event.Event) error

Publish appends e to the log and wakes every consumer. When an event with e's source and id was published within messaging.DefaultDuplicates, Publish instead drops e and returns nil.

func (*Broker) Subscribe

func (b *Broker) Subscribe(sub messaging.Subscription, report messaging.Report) (reactor.Source[event.Event], error)

Subscribe returns a source on the durable consumer that sub names, creating it on first use, at the log's beginning or, under messaging.StartNew, at its end. Sources under one Name share its position and split its work. A later subscription under an existing Name must match the first, as binding to a JetStream durable must. The source passes each message it cannot decode to report and terminates it.

Jump to

Keyboard shortcuts

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