Documentation
¶
Overview ¶
Package eventbus defines a small publish/subscribe abstraction.
Index ¶
- Constants
- Variables
- func Bind(app *runtime.App, bus Service) error
- func BindWithDriver(app *runtime.App, bus Service, driver string) error
- func CheckPublishCapability(options PublishOptions, capability Capability) error
- func CheckSubscribeCapability(options SubscribeOptions, capability Capability) error
- func CloseDefault() error
- func ContextWithEvent(ctx context.Context, event *Event) context.Context
- func DefaultDriver() string
- func EventFlowHeaderKeys() []string
- func Publish(ctx context.Context, event *Event) error
- func Register(name string, bus Service) error
- func SafeHandle(ctx context.Context, event *Event, handler Handler, log *zap.Logger) (err error)
- func SetDefault(bus Service)
- func SetDefaultWithDriver(bus Service, driver string)
- type Bus
- type Capability
- type Codec
- type Event
- type EventBus
- type Handler
- type JSONCodec
- type Manager
- type Middleware
- type PublishOption
- func WithDelay(delay time.Duration) PublishOption
- func WithHeader(key, value string) PublishOption
- func WithHeaders(headers map[string]string) PublishOption
- func WithName(name string) PublishOption
- func WithPersistent(persistent bool) PublishOption
- func WithRetry(retry int) PublishOption
- func WithTTL(ttl time.Duration) PublishOption
- func WithTraceID(traceID string) PublishOption
- type PublishOptions
- type Service
- type SubscribeOption
- type SubscribeOptions
- type Subscription
- type SubscriptionFunc
Constants ¶
View Source
const ( HeaderTraceparent = "traceparent" HeaderTracestate = "tracestate" HeaderBaggage = "baggage" HeaderTraceID = logger.TraceIDKey HeaderSpanID = logger.SpanIDKey HeaderTrackID = tracking.Header HeaderRequestID = requestid.Header HeaderConnectionID = "connection_id" HeaderSessionID = "session_id" )
View Source
const KeyEventBus runtime.Key = "eventbus"
Variables ¶
View Source
var ( ErrDefaultNotInitialized = errors.New("eventbus: default not initialized") ErrClosed = errors.New("eventbus: closed") ErrUnsupported = errors.New("eventbus: unsupported capability") ErrBusNotFound = errors.New("eventbus: bus not found") ErrNilHandler = errors.New("eventbus: nil handler") ErrEmptyTopic = errors.New("eventbus: empty topic") )
Functions ¶
func CheckPublishCapability ¶
func CheckPublishCapability(options PublishOptions, capability Capability) error
func CheckSubscribeCapability ¶
func CheckSubscribeCapability(options SubscribeOptions, capability Capability) error
func CloseDefault ¶
func CloseDefault() error
func DefaultDriver ¶
func DefaultDriver() string
func EventFlowHeaderKeys ¶
func EventFlowHeaderKeys() []string
EventFlowHeaderKeys returns the correlation headers recognized by EventFlow.
EventBus does not own these field semantics. Trace/span/request/track values are injected and extracted through core/tracecontext, core/tracking and core/requestid helpers. Connection/session values are carried only as headers and are intentionally not modeled as Event top-level fields.
func SafeHandle ¶
func SetDefault ¶
func SetDefault(bus Service)
func SetDefaultWithDriver ¶
Types ¶
type Capability ¶
type Event ¶
type Event struct {
ID string `json:"id"`
Topic string `json:"topic"`
Headers map[string]string `json:"headers,omitempty"`
Payload []byte `json:"payload,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager() *Manager
type Middleware ¶
func Logger ¶
func Logger(log *zap.Logger) Middleware
func Recover ¶
func Recover(log *zap.Logger) Middleware
func Tracing ¶
func Tracing() Middleware
type PublishOption ¶
type PublishOption func(*PublishOptions)
func WithDelay ¶
func WithDelay(delay time.Duration) PublishOption
func WithHeader ¶
func WithHeader(key, value string) PublishOption
func WithHeaders ¶
func WithHeaders(headers map[string]string) PublishOption
func WithName ¶
func WithName(name string) PublishOption
func WithPersistent ¶
func WithPersistent(persistent bool) PublishOption
func WithRetry ¶
func WithRetry(retry int) PublishOption
func WithTTL ¶
func WithTTL(ttl time.Duration) PublishOption
func WithTraceID ¶
func WithTraceID(traceID string) PublishOption
type PublishOptions ¶
type PublishOptions struct {
Name string
Headers map[string]string
TraceID string
Delay time.Duration
TTL time.Duration
Retry int
Persistent bool
}
func ApplyPublishOptions ¶
func ApplyPublishOptions(opts ...PublishOption) PublishOptions
type SubscribeOption ¶
type SubscribeOption func(*SubscribeOptions)
func WithConcurrency ¶
func WithConcurrency(concurrency int) SubscribeOption
func WithDurable ¶
func WithDurable(durable bool) SubscribeOption
func WithGroup ¶
func WithGroup(group string) SubscribeOption
type SubscribeOptions ¶
func ApplySubscribeOptions ¶
func ApplySubscribeOptions(opts ...SubscribeOption) SubscribeOptions
type Subscription ¶
type Subscription interface {
Close() error
}
type SubscriptionFunc ¶
type SubscriptionFunc func() error
func (SubscriptionFunc) Close ¶
func (fn SubscriptionFunc) Close() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.