Documentation
¶
Index ¶
Constants ¶
View Source
const (
NATS_TIMEOUT = 10 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { Kind string `json:"kind" mapstructure:"kind"` Value any `json:"data" mapstructure:"value"` Error string `json:"error" mapstructure:"error"` Meta map[string]any }
func NewErrorEvent ¶
type HandlerFunc ¶
func (HandlerFunc) HandleEvent ¶
func (h HandlerFunc) HandleEvent(e *Event) (*Event, error)
type IEventBus ¶
type IEventBus interface { Publish(e *Event) error Register(kind string, fn HandlerFunc) Request(e *Event) (*Event, error) Use(mw ...HandlerFunc) Close() error }
type NatsEventBus ¶
type NatsEventBus struct {
// contains filtered or unexported fields
}
NatsEventBus implements IEventBus using nats
func NewNatsEventBus ¶
func NewNatsEventBus(subject string, nc *nats.Conn) *NatsEventBus
func (*NatsEventBus) Close ¶
func (b *NatsEventBus) Close() error
func (*NatsEventBus) Publish ¶
func (b *NatsEventBus) Publish(e *Event) error
Publish sends an event
func (*NatsEventBus) Register ¶
func (b *NatsEventBus) Register(kind string, fn HandlerFunc)
Register a handler for a specific event kind handler is called when an event arrives. To handle publish events, register a handler and don't reply. To handle request events, register a handler and reply.
func (*NatsEventBus) Request ¶
func (b *NatsEventBus) Request(e *Event) (*Event, error)
Request sends an event and waits for a response
func (*NatsEventBus) Use ¶
func (b *NatsEventBus) Use(middleware ...HandlerFunc)
add middleware, middleware is applied in oder and called for each event
Click to show internal directories.
Click to hide internal directories.