messaging

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultShutdownTimeout = 10 * time.Second
	DefaultShutdownHandler = true
)

Variables

Functions

func ErrorsMiddleware

func ErrorsMiddleware(
	ctx context.Context,
	descriptor Descriptor,
	headers *Headers,
	msg any,
	handler HandleFn,
) error

func LoggingMiddleware

func LoggingMiddleware(
	ctx context.Context,
	descriptor Descriptor,
	headers *Headers,
	msg any,
	handler HandleFn,
) error

func RecoveryMiddleware

func RecoveryMiddleware(
	ctx context.Context,
	descriptor Descriptor,
	headers *Headers,
	msg any,
	handler HandleFn,
) error

Types

type Descriptor

type Descriptor struct {
	Namespace string `msgpack:"n"`
	Resource  string `msgpack:"r"`
	Action    string `msgpack:"a"`
}

type HandleFn

type HandleFn func(ctx context.Context, msg any) error

type HandlerOption

type HandlerOption func(*handlerConfig) error

func WithDescriptor

func WithDescriptor(descriptor Descriptor) HandlerOption

func WithHandler

func WithHandler[T proto.Message](fn func(context.Context, T) error) HandlerOption

func WithMiddlewares

func WithMiddlewares(middlewares ...Middleware) HandlerOption

type Headers

type Headers map[string]string

func (Headers) Get

func (h Headers) Get(key string) (string, bool)

type Manager

type Manager interface {
	Subscribe(ctx context.Context, router ...Router) error
	Publish(ctx context.Context, service string, message Message) error
	GetShutdownTimeout() time.Duration
	GetShutdownHandler() bool
	Shutdown(ctx context.Context, code int) error
}

func New

func New(opts ...Option) (Manager, error)

type Message

type Message struct {
	Descriptor Descriptor
	Headers    *Headers
	Body       proto.Message
}

type Middleware

type Middleware func(
	ctx context.Context,
	descriptor Descriptor,
	headers *Headers,
	msg any,
	handler HandleFn,
) error

type Option

type Option func(*manager) error

func WithPublisher

func WithPublisher(publisher message.Publisher) Option

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) Option

func WithSubscriber

func WithSubscriber(subscriber message.Subscriber) Option

func WithoutShutdownHandler

func WithoutShutdownHandler() Option

type Router

type Router interface {
	Channel() string
	WithMiddlewares(middlewares ...Middleware) *router
	RegisterHandler(opts ...HandlerOption) error
	// contains filtered or unexported methods
}

func NewRouter

func NewRouter(channel string) (Router, error)

type StatusCode

type StatusCode int

StatusCode represents an messaging status code.

const (
	StatusOK StatusCode = iota
	StatusInvalidArgument
	StatusMalformed
	StatusUnauthenticated
	StatusPermissionDenied
	StatusNotFound
	StatusAlreadyExists
	StatusConflict
	StatusFailedPrecondition
	StatusResourceExhausted
	StatusDeadlineExceeded
	StatusCanceled
	StatusUnavailable
	StatusAborted
	StatusInternalError
)

Directories

Path Synopsis
publisher
subscriber

Jump to

Keyboard shortcuts

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