notifier

package
v0.0.0-...-1f0c828 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(ctx context.Context, topic string, value interface{}) error

Publish is a wrapper utility method for NotificationWatcher.notify()

func Subscribe

func Subscribe(topic string, handler NotificationHandler) error

Subscribe is a wrapper utility method for NotificationWatcher.handle()

func UnSubscribe

func UnSubscribe(topic string, handler string) error

UnSubscribe is a wrapper utility method for NotificationWatcher.UnHandle()

Types

type HandlerChannel

type HandlerChannel struct {
	// contains filtered or unexported fields
}

HandlerChannel provides not only the chan itself but also the count of handlers related with this chan.

type HandlerIndexer

type HandlerIndexer map[string]NotificationHandler

HandlerIndexer is setup the relationship between the handler type and instance.

type Notification

type Notification struct {
	// Topic of notification
	// Required
	Topic string

	// Value of notification.
	// Optional
	Value interface{}
}

Notification wraps the topic and related data value if existing.

type NotificationHandler

type NotificationHandler interface {
	// The name of the Handler
	Name() string

	// Handle the event when it coming.
	// value might be optional, it depends on usages.
	Handle(ctx context.Context, value interface{}) error

	// IsStateful returns whether the handler is stateful or not.
	// If handler is stateful, it will not be triggered in parallel.
	// Otherwise, the handler will be triggered concurrently if more
	// than one same handler are matched the topics.
	IsStateful() bool
}

NotificationHandler defines what operations a notification handler should have.

type NotificationWatcher

type NotificationWatcher struct {
	// For handle concurrent scenario.
	*sync.RWMutex
	// contains filtered or unexported fields
}

NotificationWatcher is defined to accept the events published by the sender and match it with pre-registered notification handler and then trigger the execution of the found handler.

func NewNotificationWatcher

func NewNotificationWatcher() *NotificationWatcher

NewNotificationWatcher is constructor of NotificationWatcher.

func (*NotificationWatcher) Handle

func (nw *NotificationWatcher) Handle(topic string, handler NotificationHandler) error

Handle the related topic with the specified handler.

func (*NotificationWatcher) Notify

func (nw *NotificationWatcher) Notify(ctx context.Context, notification Notification) error

Notify that notification is coming.

func (*NotificationWatcher) UnHandle

func (nw *NotificationWatcher) UnHandle(topic string, handler string) error

UnHandle is to revoke the registered handler with the specified topic. 'handler' is optional, the type name of the handler. If it's empty value, then revoke the whole topic, otherwise only revoke the specified handler.

Directories

Path Synopsis
handler

Jump to

Keyboard shortcuts

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