handler

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package handler provides the base Handler pattern for NATS message-driven services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Settings   *config.Settings
	NATS       *natsutil.Client
	Telemetry  *telemetry.Provider
	Subject    string
	QueueGroup string
	// contains filtered or unexported fields
}

Handler is the base service runner that wires NATS, health, and telemetry.

func New

func New(subject string, settings *config.Settings) *Handler

New creates a Handler for the given NATS subject.

func (*Handler) OnSetup

func (h *Handler) OnSetup(fn SetupFunc)

OnSetup registers the setup callback.

func (*Handler) OnTeardown

func (h *Handler) OnTeardown(fn TeardownFunc)

OnTeardown registers the teardown callback.

func (*Handler) OnTypedMessage

func (h *Handler) OnTypedMessage(fn TypedMessageHandler)

OnTypedMessage registers the message handler callback.

func (*Handler) Run

func (h *Handler) Run() error

Run starts the handler: telemetry, health server, NATS subscription, and blocks until SIGTERM/SIGINT.

type SetupFunc

type SetupFunc func(ctx context.Context) error

SetupFunc is called once before the handler starts processing messages.

type TeardownFunc

type TeardownFunc func(ctx context.Context) error

TeardownFunc is called during graceful shutdown.

type TypedMessageHandler

type TypedMessageHandler func(ctx context.Context, msg *nats.Msg) (proto.Message, error)

TypedMessageHandler processes the raw NATS message. Services unmarshal msg.Data into their own typed structs via natsutil.Decode. Return a proto.Message (or nil for no reply).

Jump to

Keyboard shortcuts

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