handlers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildJSONHandler

func BuildJSONHandler[T any, O any](handler JSONMessageHandler[T, O]) (message.HandlerFunc, error)

BuildJSONHandler converts a typed JSON handler into a Watermill handler.

func BuildProtoHandler

func BuildProtoHandler[T proto.Message](prototype T, handler ProtoMessageHandler[T], validate func(proto.Message) error, factory ProtoMessageFactory) (message.HandlerFunc, error)

BuildProtoHandler converts the typed handler into a Watermill handler using the provided factory.

func EnsureProtoPrototype

func EnsureProtoPrototype[T proto.Message](candidate T) (T, error)

Types

type JSONHandlerRegistration

type JSONHandlerRegistration[T any, O any] struct {
	Name         string
	ConsumeQueue string
	PublishQueue string
	Handler      JSONMessageHandler[T, O]
}

JSONHandlerRegistration wires a typed JSON handler to the router.

type JSONMessageContext

type JSONMessageContext[T any] struct {
	Payload  T
	Metadata metadatapkg.Metadata
}

JSONMessageContext exposes the incoming payload and metadata for JSON handlers.

func (JSONMessageContext[T]) CloneMetadata

func (c JSONMessageContext[T]) CloneMetadata() metadatapkg.Metadata

CloneMetadata copies the current metadata map so handlers can mutate headers safely.

type JSONMessageHandler

type JSONMessageHandler[T any, O any] func(ctx context.Context, event JSONMessageContext[T]) ([]JSONMessageOutput[O], error)

JSONMessageHandler processes a JSON payload and returns the events to publish.

type JSONMessageOutput

type JSONMessageOutput[T any] struct {
	Message  T
	Metadata metadatapkg.Metadata
}

JSONMessageOutput represents an event emitted by a JSON handler.

type ProtoHandlerOption

type ProtoHandlerOption func(*protoHandlerOptions)

ProtoHandlerOption customises handler registration.

func WithPublishMessageTypes

func WithPublishMessageTypes(msgs ...proto.Message) ProtoHandlerOption

WithPublishMessageTypes registers extra proto schemas emitted by this handler. Use this when the handler may emit multiple message types.

type ProtoHandlerOptions

type ProtoHandlerOptions struct {
	AdditionalPublishTypes []proto.Message
}

ProtoHandlerOptions exposes the resolved handler configuration to callers.

func ApplyProtoHandlerOptions

func ApplyProtoHandlerOptions(opts []ProtoHandlerOption) ProtoHandlerOptions

ApplyProtoHandlerOptions resolves the supplied options into a concrete configuration.

type ProtoHandlerRegistration

type ProtoHandlerRegistration[T proto.Message] struct {
	Name             string
	ConsumeQueue     string
	PublishQueue     string
	Handler          ProtoMessageHandler[T]
	Options          []ProtoHandlerOption
	ValidateOutgoing bool
}

ProtoHandlerRegistration configures a typed protobuf handler that automatically unmarshals incoming payloads and marshals emitted events.

type ProtoMessageContext

type ProtoMessageContext[T proto.Message] struct {
	Payload  T
	Metadata metadatapkg.Metadata
}

ProtoMessageContext provides strongly typed access to the incoming message payload.

func (ProtoMessageContext[T]) CloneMetadata

func (c ProtoMessageContext[T]) CloneMetadata() metadatapkg.Metadata

CloneMetadata returns a copy of the current metadata map so handlers can safely mutate headers for outgoing events without touching the original map.

type ProtoMessageFactory

type ProtoMessageFactory func(proto.Message, metadatapkg.Metadata) (*message.Message, error)

ProtoMessageFactory converts proto payloads into Watermill messages.

type ProtoMessageHandler

type ProtoMessageHandler[T proto.Message] func(ctx context.Context, event ProtoMessageContext[T]) ([]ProtoMessageOutput, error)

ProtoMessageHandler processes a typed protobuf payload and returns the events to emit.

type ProtoMessageOutput

type ProtoMessageOutput struct {
	Message  proto.Message
	Metadata metadatapkg.Metadata
}

ProtoMessageOutput describes an event that should be emitted after the handler succeeds.

Jump to

Keyboard shortcuts

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