postgres

package
v2.10.1 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres is the fanout.Bus over Postgres LISTEN/NOTIFY, so a deployment whose state is in Postgres needs no second service for fan-out (docs/adr/0008).

Each Bus holds one connection of its own that listens on one channel, whatever the number of topics or subscribers: the topic travels in the payload and the Bus delivers by it. When that connection drops, the Bus reconnects and listens again. Messages sent while it was away are lost, which the port allows: the engine treats every message as a hint and converges without it.

Index

Constants

View Source
const Channel = "cartograph_fanout"

Channel is the one NOTIFY channel every replica listens on.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus is one replica's connection to the fan-out.

func New

func New(ctx context.Context, pool *pgxpool.Pool, opts ...Option) (*Bus, error)

New publishes through pool and listens on a connection of its own, configured as the pool's connections are unless ListenOn says otherwise. It returns once that connection is listening, so a message published after New returns reaches this Bus's subscribers.

func (*Bus) Close

func (b *Bus) Close() error

Close stops listening and ends every subscription.

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, topic string, data []byte) error

Publish sends data to topic's subscribers on every replica.

func (*Bus) Subscribe

func (b *Bus) Subscribe(ctx context.Context, topic string) (fanout.Subscription, error)

Subscribe delivers topic's messages until ctx ends or the subscription is closed.

type Option added in v2.1.0

type Option func(*Bus) error

Option configures a Bus.

func ListenOn added in v2.1.0

func ListenOn(url string) Option

ListenOn makes the listening connection reach Postgres at url instead of through the pool's settings. LISTEN needs a session of its own, so when the pool goes through a pooler in transaction mode (PgBouncer's usual setting), where LISTEN does not work, url must reach Postgres directly. Publishing (pg_notify) works through any pooler and stays on the pool.

Jump to

Keyboard shortcuts

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