jetconsumer

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFoundHandler = HandlerFunc(func(_ context.Context, _ jetstream.Msg) error {
	return peanats.Error{
		Code:    http.StatusNotFound,
		Message: "handler not found",
		Cause:   nil,
	}
})

Functions

This section is empty.

Types

type AccessLogOption added in v0.8.2

type AccessLogOption func(*accessLogParams)

func WithAccessLogLevel added in v0.8.2

func WithAccessLogLevel(level slog.Level) AccessLogOption

func WithAccessLogMessage added in v0.8.2

func WithAccessLogMessage(message string) AccessLogOption

type Consumer

type Consumer struct {
	BaseContext context.Context
	Consumer    JetstreamConsumer
	Handler     Handler
	Executor    func(func())
	// contains filtered or unexported fields
}

func (*Consumer) Start added in v0.7.3

func (c *Consumer) Start() (err error)

func (*Consumer) Stop added in v0.7.3

func (c *Consumer) Stop()

type Handler

type Handler interface {
	Serve(ctx context.Context, msg jetstream.Msg) error
}

func ChainMiddleware added in v0.7.3

func ChainMiddleware(h Handler, mws ...Middleware) Handler

func HandleType added in v0.8.0

func HandleType[T any](h TypedHandler[T]) Handler

type HandlerFunc added in v0.7.2

type HandlerFunc func(ctx context.Context, msg jetstream.Msg) error

func (HandlerFunc) Serve added in v0.7.2

func (f HandlerFunc) Serve(ctx context.Context, msg jetstream.Msg) error

type JetstreamConsumer added in v0.7.3

type JetstreamConsumer interface {
	Consume(jetstream.MessageHandler, ...jetstream.PullConsumeOpt) (jetstream.ConsumeContext, error)
}

type Middleware

type Middleware func(handler Handler) Handler

func Router added in v0.7.3

func Router(routes ...Route) Middleware

func WithAccessLog

func WithAccessLog(logger *slog.Logger, opts ...AccessLogOption) Middleware

WithAccessLog returns a middleware that logs access using the provided slog.Logger.

func WithAck

func WithAck() Middleware

WithAck returns a middleware that ACKs the message after handling it successfully.

func WithAckOnArrival added in v0.9.3

func WithAckOnArrival() Middleware

WithAckOnArrival returns a middleware that ACKs the message immediately on arrival.

func WithErrorLog

func WithErrorLog(logger *slog.Logger, propagate bool) Middleware

WithErrorLog returns a middleware that logs errors using the provided logger. If propagate is true, the error is propagated to the outer handler.

func WithNak added in v0.6.4

func WithNak() Middleware

WithNak returns a middleware that NAKs the message if the handler returns an error.

type Route added in v0.7.3

type Route interface {
	peanats.Matcher
	Handler
}

func Handle added in v0.7.3

func Handle(subj string, handler Handler) Route

type TypedHandler added in v0.7.3

type TypedHandler[T any] interface {
	Serve(context.Context, TypedMessage[T]) error
}

type TypedHandlerFunc added in v0.7.3

type TypedHandlerFunc[T any] func(peanats.TypedRequest[T]) error

func (TypedHandlerFunc[T]) Serve added in v0.7.3

func (f TypedHandlerFunc[T]) Serve(arg peanats.TypedRequest[T]) error

type TypedMessage added in v0.7.3

type TypedMessage[T any] interface {
	jetstream.Msg
	Payload() *T
}

Jump to

Keyboard shortcuts

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