messaging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package messaging holds broker-agnostic primitives shared by every messaging transport in the kit (AMQP, NATS, and future brokers). The goal is that a service's handler / encoder / decoder code reads the same regardless of which broker delivers the message, so the broker can be swapped at the wire layer without touching the application layer.

The transport packages re-export these types under their own names (e.g. amqp.Handler is messaging.Handler) so existing code keeps working; new code should import this package directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONDecoder

func JSONDecoder[T any](_ context.Context, payload []byte) (T, error)

JSONDecoder is a ready-made Decoder for JSON payloads. Mirror of JSONEncoder for the consumer side.

func JSONEncoder

func JSONEncoder[T any](_ context.Context, v T) ([]byte, error)

JSONEncoder is a ready-made Encoder for JSON payloads. Most services can use this directly instead of writing a per-type encoder.

Types

type Decoder

type Decoder[T any] func(ctx context.Context, payload []byte) (T, error)

Decoder is the inverse of Encoder: given a payload (and any broker metadata the transport extracted into ctx) it returns the decoded value or an error.

type Encoder

type Encoder[T any] func(ctx context.Context, v T) ([]byte, error)

Encoder turns an application value into the byte payload that goes on the wire. Returns an error if the value cannot be marshalled.

type Handler

type Handler[T any] interface {
	Handle(ctx context.Context, event T) error
}

Handler is implemented by application code that consumes events. Returning a non-nil error signals the transport to nack / retry the message according to its semantics.

type HandlerFunc

type HandlerFunc[T any] func(ctx context.Context, event T) error

HandlerFunc adapts a plain function to the Handler interface.

func (HandlerFunc[T]) Handle

func (f HandlerFunc[T]) Handle(ctx context.Context, event T) error

Handle satisfies the Handler interface.

Jump to

Keyboard shortcuts

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