haro

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 4 Imported by: 0

README

Haro

Topic-based pubsub library.

go report card test Coverage Status Go.Dev reference

Usage

Install with:

go get github.com/dewadg/haro
Declaring topic
intTopic := haro.DeclareTopic[int]()

stringTopic := haro.DeclareTopic[string]()
Registering subscribers
intTopic.Subscribe(func(ctx context.Context, p int) error {
    return nil
})

stringTopic.Subscribe(func(ctx context.Context, p string) error {
    return nil
})
Publishing
var err error

err = intTopic.Publish(context.Background(), 5)

err = stringTopic.Publish(context.Background(), "test")

Limitations

  • It's not a distributed pubsub mechanism, it means pubsub across different instances won't work (eg: across docker container replication)
  • No recovery since it doesn't utilize any external storage, it's purely using Channel to store the published messages

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPayloadTypeMismatch = errors.New("Mismatch parameter between subscriber and event payload")

ErrPayloadTypeMismatch indicates if the payload type between subscriber and event not match

View Source
var ErrSubscriberInvalidFirstParameter = errors.New("Subscriber should have `context.Context` as the first parameter")

ErrSubscriberInvalidFirstParameter indicates if the subscriber's first parameter should be context.Context

View Source
var ErrSubscriberInvalidFirstReturnType = errors.New("Subscriber should have return type `error`")

ErrSubscriberInvalidFirstReturnType indicates if the subscriber's return type should be error

View Source
var ErrSubscriberInvalidParameters = errors.New("Subscriber should have exactly 2 parameters")

ErrSubscriberInvalidParameters indicates if the subscriber doesn't have 2 parameters

View Source
var ErrSubscriberInvalidReturnTypes = errors.New("Subscriber should have 1 return type")

ErrSubscriberInvalidReturnTypes indicates if the subscriber should only have 1 return type

View Source
var ErrSubscriberNotAFunction = errors.New("Subscriber should be a function")

ErrSubscriberNotAFunction indicates if the subscriber is not a function

Functions

This section is empty.

Types

type Subscriber

type Subscriber[Payload any] func(context.Context, Payload) error

type SubscriberConfigFunc added in v1.3.0

type SubscriberConfigFunc func(*subscriberConfig)

SubscriberConfigFunc is signature of function for doing configuration

func DelayRetry

func DelayRetry(delay time.Duration) SubscriberConfigFunc

DelayRetry configures delay between each retry

func OnError

func OnError(onError func(error)) SubscriberConfigFunc

OnError specify what to do when error occured

func OnSuccess added in v1.1.0

func OnSuccess(onSuccess func()) SubscriberConfigFunc

OnSuccess specify what to do when no error occured

func Retry

func Retry(count int) SubscriberConfigFunc

Retry configures how many times should the subscriber retries before really failing

type Topic added in v1.2.0

type Topic[Payload any] interface {
	Publish(context.Context, Payload) error

	Subscribe(sub Subscriber[Payload], configurators ...SubscriberConfigFunc)
}

func DeclareTopic added in v1.2.0

func DeclareTopic[Payload any]() Topic[Payload]

Jump to

Keyboard shortcuts

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