By defining a concrete, non-protobuf type for the events interface, we can completely decouple it from the grpc packages that are expensive at runtime. This does requires some allocation cost for converting between types, but the saving for the size of the shim are worth it. Signed-off-by: Stephen J Day <stephen.day@docker.com>
35 lines
756 B
Go
35 lines
756 B
Go
package events
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gogo/protobuf/types"
|
|
)
|
|
|
|
// Envelope provides the packaging for an event.
|
|
type Envelope struct {
|
|
Timestamp time.Time
|
|
Namespace string
|
|
Topic string
|
|
Event *types.Any
|
|
}
|
|
|
|
// Event is a generic interface for any type of event
|
|
type Event interface{}
|
|
|
|
// Publisher posts the event.
|
|
type Publisher interface {
|
|
Publish(ctx context.Context, topic string, event Event) error
|
|
}
|
|
|
|
// Forwarder forwards an event to the underlying event bus
|
|
type Forwarder interface {
|
|
Forward(ctx context.Context, envelope *Envelope) error
|
|
}
|
|
|
|
// Subscriber allows callers to subscribe to events
|
|
type Subscriber interface {
|
|
Subscribe(ctx context.Context, filters ...string) (ch <-chan *Envelope, errs <-chan error)
|
|
}
|