bus

package module
v0.0.0-...-ace6e0c Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: Apache-2.0 Imports: 2 Imported by: 6

README

Event bus golang implementation

GoDoc

Golang event bus library with service discovery and protobuf support. This repository provides the basic types required to implement event bus pattern.

Publisher implementations

Publishers registry implementations

Subscriber implementations

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event[Payload proto.Message] struct {
	EventKey     EventKey
	EventPayload Payload
}

Event contains data for publishing.

type EventFilter

type EventFilter string

EventFilter is used for filtering inbound events by EventKey. Event will be passed if event key starts with EventFilter value.

type EventKey

type EventKey string

EventKey is used for group and route events. Events with same event key value must be consumed by same consumer.

type EventName

type EventName string

EventName determines type of event content.

type EventVersion

type EventVersion int

EventVersion determines version of event content.

type Publisher

type Publisher[Payload proto.Message] interface {
	// Publish serializes passed events to protobuf and publishes passed events in same order as it was passed to method call.
	Publish(ctx context.Context, events []Event[Payload]) error
	// Stop releases resources allocated for Publisher.
	Stop() error
}

Publisher writes events to events transport or to Subscriber's directly.

type PublisherEndpoint

type PublisherEndpoint string

PublisherEndpoint is publisher network address in format `IP_ADDRESS:PORT`.

type PublishersRegistry

type PublishersRegistry interface {
	// Register adds record about publisher endpoint to registry and returns unregister function which removes registered publisher from registry.
	Register(eventName EventName, eventVersion EventVersion, host string, port int) (unregister func() error, err error)
	// Watch creates watcher for publishers endpoints list updates and returns function for stop created watcher.
	Watch(eventName EventName, eventVersion EventVersion, handler func([]PublisherEndpoint)) (stop func() error, err error)
}

PublishersRegistry allows to register/unregister and watch publishers which can write to Subscriber's directly.

type Subscriber

type Subscriber[Payload proto.Message] interface {
	// EventsChan returns channel for receiving events matched with EventFilter.
	EventsChan() <-chan Event[Payload]
	// Stop removes subscriptions and releases resources allocated for Subscriber.
	Stop() error
	// Subscribe creates subscription for EventFilter.
	Subscribe(eventFilter EventFilter) error
	// Unsubscribe removes subscription for EventFilter.
	Unsubscribe(eventFilter EventFilter) error
}

Subscriber provides functions for subscribe/unsubscribe on specific EventName and EventVersion. One instance of Subscriber can't subscribe/unsubscribe on more than one pair of EventName and EventVersion.

Jump to

Keyboard shortcuts

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