Documentation
¶
Index ¶
- Variables
- func BuilderAction[T, R any](hb *handlerBuilder, handler func(ctx context.Context, input T) (R, error))
- func BuilderActionEvent[T any](hb *handlerBuilder, handler func(ctx context.Context, input T) error)
- func Emit(ctx context.Context, b *Broker, pattern string, payload any) error
- func Handle[T, R any](b *Broker, pattern string, ...)
- func HandleBuilder[T, R any](b *Broker, pattern string) *handlerBuilder
- func On[T any](b *Broker, pattern string, handler func(ctx context.Context, input T) error)
- func OnBuilder[T any](b *Broker, pattern string) *handlerBuilder
- func Provider() ligo.Provider
- func RabbitMQModule(cfg RabbitMQConfig) ligo.Module
- func Send[T any](ctx context.Context, b *Broker, pattern string, payload any) (T, error)
- type Broker
- type BrokerError
- type Codec
- type HandlerBuilder
- type Message
- type MessageExceptionFilter
- type MessageGuard
- type MessageInterceptor
- type MessagePipe
- type RabbitMQConfig
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotConnected is returned by Send when the broker has not yet // connected (or has been shut down). ErrNotConnected = errors.New("microservices: broker not connected") // ErrConnectionLost is returned to in-flight Send callers when the // broker's underlying AMQP connection drops mid-request. The reply // channel is drained as part of reconnect, so the caller gets a // determinate error instead of timing out. ErrConnectionLost = errors.New("microservices: connection lost during request") )
Functions ¶
func BuilderAction ¶
func BuilderActionEvent ¶
func HandleBuilder ¶
func On ¶
On registers a typed event handler for the given pattern. Panics if a handler is already registered for the same pattern.
func Provider ¶
Provider returns a ligo.Provider that registers a *Broker as a singleton. Use this when you need fine-grained control over module composition.
func RabbitMQModule ¶
func RabbitMQModule(cfg RabbitMQConfig) ligo.Module
RabbitMQModule returns a ligo module that registers a *Broker provider with the given configuration. The broker connects during OnInit and disconnects during OnShutdown.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
func NewBroker ¶
func NewBroker(cfg RabbitMQConfig) *Broker
func (*Broker) Register ¶
func (b *Broker) Register(r *ligo.HookRegistry)
type BrokerError ¶
BrokerError is a structured error that travels over the wire during RPC.
func Validation ¶
func Validation(msg string) *BrokerError
Validation creates a "Validation" broker error.
func (*BrokerError) Error ¶
func (e *BrokerError) Error() string
type Codec ¶
Codec encodes and decodes message payloads.
var JSONCodec Codec = jsonCodec{}
JSONCodec uses encoding/json.
var ProtobufCodec Codec = protobufCodec{}
ProtobufCodec uses google.golang.org/protobuf. Values must implement proto.Message.
type HandlerBuilder ¶
type HandlerBuilder interface {
Guard(guards ...MessageGuard) *handlerBuilder
Pipe(pipes ...MessagePipe) *handlerBuilder
Intercept(interceptors ...MessageInterceptor) *handlerBuilder
Filter(filters ...MessageExceptionFilter) *handlerBuilder
}
type MessageExceptionFilter ¶
type MessageGuard ¶
MessageGuard returns (true, nil) to allow, (false, error) to deny.
type MessageInterceptor ¶
MessageInterceptor wraps handler execution. Call next() to continue the chain.
type RabbitMQConfig ¶
type RabbitMQConfig struct {
URL string
Exchange string
Queue string
Codec Codec
Timeout time.Duration
Retry RetryConfig
}
RabbitMQConfig holds configuration for the RabbitMQ transport.
Queue controls the handler queue declaration:
- "" (default): server-generated name, exclusive, auto-delete, non-durable. One queue per broker instance; gone when the process exits. Good for ephemeral RPC clients and single-process demos.
- non-empty: the given name, durable, non-exclusive, non-auto-delete. Survives restarts and can be shared by multiple consumers (worker pool / competing consumers).