Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFn ¶
type HandlerFn func(event cloudevents.Event, parentSpanCtx context.Context) error
HandlerFn is a function that is called when a cloudevent is received at a subscriber.
type Publisher ¶
type Publisher interface { // Publish publishes any data to the given topic. // A topic needs to be passed to which the publisher publisheds the data. // The data can be of any arbitrary type. Publish(topic string, data any, spanCtx ...trace.SpanContext) error }
type Subscriber ¶
type Subscriber interface { // Subscribe registers a subscriber at the registry. // A topic needs to be passed from which the subscriber will receive events. // The handler function is called when an event is received. Subscribe(topic string, handler HandlerFn) error // Unsubscribe removes a subscriber from the registry. // The handler function of the handler to remove has to be passed. Unsubscribe(handler HandlerFn) error }
type UnsubscribeFn ¶
type UnsubscribeFn func()
UnsubscribeFn is a function to unsubscribe a handler.
func Chan ¶
func Chan[T any](subscriber Subscriber, topic string, match ...func(event T) bool) (<-chan T, UnsubscribeFn, error)
Chan is a convenience function for creating a channel to an event handler. A subscriber has to be passed on which the internal handler gets registered. A topic needs to be passed from which the subscriber will receive events. A match function can be passed to filter events, reaching the channel. The method returns a channel and a function to unsubscribe the handler.
func On ¶
func On[T any](handlerFn func(event T, spanContext context.Context) error, subscriber Subscriber, topic string) (UnsubscribeFn, error)
On is a convenience function for creating a handler that executes only if the type can be parsed. A subscriber has to be passed on which the internal handler gets registered. A topic needs to be passed from which the subscriber will receive events. The method returns a function to unsubscribe the handler.