backends

package
v3.15.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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