Documentation ¶
Index ¶
- Variables
- func Listen(e *EventBus, c Client) error
- func RegisterClient(name string, c Client)
- func Retry(fn func() error, times int, delay *time.Duration) error
- func Wait(delay time.Duration)
- type Client
- type Event
- type EventBus
- type EventDispatcher
- type EventHandler
- type EventPayload
- type GooglePubSub
- type RedisPubSub
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEventNotFound = errors.New("event not found")
View Source
var ErrInvalidPayload = errors.New("invalid payload")
Functions ¶
func RegisterClient ¶
Types ¶
type Client ¶
type EventBus ¶
type EventBus struct { // Context is the context for the event client Context context.Context // Connection is the connection string to the event bus Connection string // EventHandlers is a list of event handlers EventHandlers []EventHandler // contains filtered or unexported fields }
func (*EventBus) RegisterEvents ¶
func (c *EventBus) RegisterEvents(events ...EventHandler)
type EventDispatcher ¶
EventDispatcher is a function that dispatches an event
type EventHandler ¶
type EventHandler interface { // GetEventName returns the name of the event GetEventName() Event // GetSubscriptionID returns the subscription id GetSubscriptionID() string // GetContext returns the context GetContext() context.Context // ValidatePayload validates the event payload ValidatePayload(payload []byte) error // Handle handles the event Handle(ctx context.Context, body []byte) error }
type EventPayload ¶
type EventPayload struct { Event Event `json:"event"` Payload struct { Version string `json:"version"` Timestamp int64 `json:"timestamp"` Data json.RawMessage `json:"data"` } `json:"payload"` }
EventPayload is the payload that is sent to the event handler
type GooglePubSub ¶
func NewGooglePubSub ¶
func NewGooglePubSub() *GooglePubSub
func (*GooglePubSub) Connect ¶
func (g *GooglePubSub) Connect(ctx context.Context, conn string) error
func (*GooglePubSub) Subscribe ¶
func (c *GooglePubSub) Subscribe(dispatch EventDispatcher, events ...EventHandler) error
type RedisPubSub ¶
type RedisPubSub struct { }
func NewRedisPubSub ¶
func NewRedisPubSub() *RedisPubSub
func (*RedisPubSub) Close ¶
func (c *RedisPubSub) Close() error
func (*RedisPubSub) Subscribe ¶
func (c *RedisPubSub) Subscribe(dispatch EventDispatcher, events ...EventHandler) error
Click to show internal directories.
Click to hide internal directories.