eventbus

package
v0.0.0-...-83cf971 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Kind describes the type of the event.
	Kind string `json:"kind"`

	// ID of this event instance, used to deduplicate events.
	ID string `json:"id"`

	// CreatedAt represents the time that the event was created.
	CreatedAt time.Time `json:"created_at"`

	// Payload will loose type information when deserializing JSON. If
	// initially a structure was given, JSON will unmarshall it to
	// map[string]interface{}. This is ok as long as the event published
	// does not see a difference between those two.
	Payload interface{} `json:"payload"`
}

type RecordingSink

type RecordingSink struct {
	Events []Event
}

RecordingSink drops all published events, storing locally their data and ID. Use for testing.

func (*RecordingSink) AssertPublished

func (s *RecordingSink) AssertPublished(t testing.TB, events ...Event)

func (*RecordingSink) PublishEvent

func (s *RecordingSink) PublishEvent(ctx context.Context, e Event) error

type Sink

type Sink interface {
	// PublishEvent sends an event to the subscriber using mechanism
	// provided by the Sink implementation. It is up to the implementation
	// to decide how to serialize the data.
	//
	// Each event should be published with a unique identifier. Since the
	// delivery is at least once, ID allows for deduplication by the
	// client.
	PublishEvent(context.Context, Event) error
}

Sink interface is implemented by multiple backends to allow various ways of subscribing to application events.

func NewFsSink

func NewFsSink(dir string) Sink

NewFsSink returns a Sink implementation that writes all events as separate files to given directory.

This implementation must be used only for local development or tests. Be aware that publishing a lot of events will cause creation of a lot of files in a single directory.

func NewNoopSink

func NewNoopSink() Sink

NewNoopSink returns a Sink implementation that drops all events.

func NewWebhookSink

func NewWebhookSink(url string, secret []byte, client *http.Client) Sink

NewWebhookSink returns a Sink implementation that is publishing events by making an HTTP POST request to given URL. Payload is JSON serialized.

func ThroughTaskQueue

func ThroughTaskQueue(sink Sink, queue *taskqueue.Registry) Sink

ThroughTaskQueue wraps given sink so that all published events are first written to the task queue. The actual event publishing is done by each task consumed from the queue.

This function registers a task handler within given task queue registry.

Using this implementation can provide additional assurance that the event will be delivered despite temporary issues. Use it together with for example the webhook sink in order to mitigate connection issues or temporary recipient failure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL