1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-26 03:52:12 +02:00
kratos/event/event.go

35 lines
836 B
Go
Raw Normal View History

2021-03-20 16:59:47 +08:00
package event
import (
"context"
)
2021-03-22 19:01:25 +08:00
// Event is an absctraction for all messages that
// are sent to quque or received from queue.
2021-03-22 19:01:25 +08:00
type Event struct {
// Key sets the key of the message for routing policy
Key string
// Payload for the message
Payload []byte
// Properties attach application defined properties on the message
Properties map[string]string
}
// Handler is a callback function that processes messages delivered
// to asynchronous subscribers.
type Handler func(context.Context, Event) error
// Publisher is absctraction for sending messages
// to queue.
type Publisher interface {
2021-03-22 19:01:25 +08:00
Publish(ctx context.Context, event Event) error
Close() error
}
// Subscriber is an absctraction for receiving messages
// from queue.
type Subscriber interface {
Subscribe(ctx context.Context, h Handler) error
Close() error
}