events

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEvent              = errors.Define("event.invalid")
	ErrEventPayloadSerialization = errors.Define("event.payload_serialization")
	ErrEventInternal             = errors.Define("event.internal")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event

func CreateEvent

func CreateEvent(
	entityId string,
	topic string,
	payload interface{},
) (*Event, error)

func NewEvent

func NewEvent(
	id string,
	entityId string,
	topic string,
	payload []byte,
	timestamp time.Time,
) (*Event, error)

func (*Event) EntityId

func (e *Event) EntityId() string

func (*Event) Id

func (e *Event) Id() string

func (*Event) Payload

func (e *Event) Payload() []byte

func (*Event) Timestamp

func (e *Event) Timestamp() time.Time

func (*Event) Topic

func (e *Event) Topic() string

func (*Event) UnmarshalPayload

func (e *Event) UnmarshalPayload(v interface{}) error

type EventCollector

type EventCollector struct {
	// contains filtered or unexported fields
}

func CreateEventCollector

func CreateEventCollector() *EventCollector

func NewEventCollector

func NewEventCollector(events []*Event) *EventCollector

func (*EventCollector) All

func (c *EventCollector) All() []*Event

func (*EventCollector) Drain

func (c *EventCollector) Drain() []*Event

func (*EventCollector) Record

func (c *EventCollector) Record(p Publishable) error

type Handler

type Handler interface {
	Handle(ctx context.Context, event *Event) error
}

type LocalEventBus

type LocalEventBus struct {
	// contains filtered or unexported fields
}

func NewLocalEventBus

func NewLocalEventBus() *LocalEventBus

func (*LocalEventBus) Publish

func (eb *LocalEventBus) Publish(ctx context.Context, events ...*Event) error

func (*LocalEventBus) Subscribe

func (eb *LocalEventBus) Subscribe(ctx context.Context, subject string, handler Handler) error

type NatsEvent

type NatsEvent struct {
	Id        string    `json:"id"`
	EntityId  string    `json:"entity_id"`
	Topic     string    `json:"topic"`
	Payload   []byte    `json:"payload"`
	Timestamp time.Time `json:"timestamp"`
}

type NatsEventBus

type NatsEventBus struct {
	// contains filtered or unexported fields
}

func NewNatsEventBus

func NewNatsEventBus(
	consumerGroup string,
	conn *nats.Conn,
) *NatsEventBus

func (*NatsEventBus) Publish

func (eb *NatsEventBus) Publish(ctx context.Context, events ...*Event) error

func (*NatsEventBus) Subscribe

func (eb *NatsEventBus) Subscribe(ctx context.Context, subject string, handler Handler) error

type Publishable

type Publishable interface {
	Id() string
	Topic() string
}

type Publisher

type Publisher interface {
	Publish(ctx context.Context, events ...*Event) error
}

Publisher and subscriber

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, subject string, handler Handler) error
}

Jump to

Keyboard shortcuts

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