backends

package
v3.12.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Publish(ctx context.Context, envelope model.Envelope) error
}

Backend publishes accepted notifications to the delivery backend.

type NATSBackend

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

NATSBackend publishes accepted notifications to JetStream.

func NewNATSBackend

func NewNATSBackend(conf NATSConfig, log zerolog.Logger) (*NATSBackend, error)

NewNATSBackend connects to NATS and ensures the notification stream exists.

func (*NATSBackend) Close

func (b *NATSBackend) Close() error

Close drains the NATS connection.

func (*NATSBackend) Publish

func (b *NATSBackend) Publish(_ context.Context, envelope model.Envelope) error

Publish implements Backend.

type NATSConfig

type NATSConfig struct {
	Address string `mapstructure:"address"`
	Token   string `mapstructure:"token"`
	Stream  string `mapstructure:"stream"`
	Subject string `mapstructure:"subject"`
	Durable string `mapstructure:"durable"`
	Queue   string `mapstructure:"queue"`
	// Namespace scopes the stream, subject, durable and queue names so
	// environments sharing one NATS server (for example QA, test and dev on the
	// same host) each get their own isolated stream and queue group instead of
	// consuming each other's events. Publisher and consumer must set the same
	// value. Ignored for any name given explicitly above.
	Namespace string `mapstructure:"namespace"`
}

NATSConfig configures the NATS notification backend and listener.

type NATSListener

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

NATSListener consumes notification envelopes from JetStream.

func NewNATSListener

func NewNATSListener(conf NATSConfig, log zerolog.Logger) (*NATSListener, error)

NewNATSListener connects to NATS and ensures the notification stream exists.

func (*NATSListener) Close

func (l *NATSListener) Close() error

Close drains the NATS listener connection.

func (*NATSListener) Queue

func (l *NATSListener) Queue() string

Queue returns the queue group the listener joins.

func (*NATSListener) Start

func (l *NATSListener) Start(ctx context.Context, handler func(context.Context, model.Envelope) error) error

Start subscribes to the notification stream. Messages are acked only when the handler returns nil.

func (*NATSListener) Stream

func (l *NATSListener) Stream() string

Stream returns the JetStream stream the listener consumes from.

func (*NATSListener) Subject

func (l *NATSListener) Subject() string

Subject returns the subject the listener is subscribed to.

Jump to

Keyboard shortcuts

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