memory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memory provides an in-process backplane.Backplane using Go channels.

This adapter is intended for testing multi-node scenarios in a single process. It is NOT suitable for production deployments.

Standalone usage

bp := memory.New("node-1")

Multi-node testing with a Hub

hub := memory.NewHub()
bp1 := memory.NewWithHub("node-1", hub)
bp2 := memory.NewWithHub("node-2", hub)

Characteristics

  • Subscriber channels are buffered (capacity 64). Messages are dropped if a subscriber falls behind.
  • Hub connects multiple backplanes so a message published by one is delivered to all others.
  • Self-message filtering is handled by the adapter: subscribers skip messages whose SourceID matches the local node ID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backplane

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

Backplane is an in-process backplane.Backplane that broadcasts messages via Go channels. All subscribers in the same process receive every message.

Create one with New for standalone use or NewWithHub for multi-node testing.

func New

func New(nodeID string) *Backplane

New creates a standalone Backplane that only delivers to its own subscribers.

func NewWithHub

func NewWithHub(nodeID string, hub *Hub) *Backplane

NewWithHub creates a Backplane connected to hub so that published messages are delivered to all other backplanes registered on the same Hub.

func (*Backplane) Close

func (b *Backplane) Close() error

func (*Backplane) Publish

func (b *Backplane) Publish(_ context.Context, msg backplane.Message) error

func (*Backplane) Subscribe

func (b *Backplane) Subscribe(handler backplane.Handler) (cancel func(), err error)

type Hub

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

Hub connects multiple in-process Backplane instances so that a message published by one is delivered to all others. Use NewHub to create a hub, then NewWithHub to create backplanes that share it.

func NewHub

func NewHub() *Hub

NewHub creates a shared Hub for connecting multiple in-process backplanes.

Jump to

Keyboard shortcuts

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