pubsub

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput = fmt.Errorf("invalid input")
	ErrTimeout      = fmt.Errorf("timeout")
)

Functions

This section is empty.

Types

type CancelFunc

type CancelFunc func()

CancelFunc removes the associated listener with and cancels any future events sent to that listener.

A CancelFunc is idempotent: after the first invocation, calling this closure will have no effect.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the interface implemented by types that can be used to configure the credentials.

func Normify

func Normify(opts ...wrp.NormifierOption) Option

Normify is an option that sets the desired normalization options used to normalize/validate the wrp message.

As an example, if you want all messages to contain metadata about something like the network interface used, this is the place to define it.

func WithEgressHandler

func WithEgressHandler(handler wrpkit.Handler, cancel ...*CancelFunc) Option

WithEgressHandler is an option that adds a handler for egress messages. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the subscription.

func WithEventHandler

func WithEventHandler(event string, handler wrpkit.Handler, cancel ...*CancelFunc) Option

WithEventHandler is an option that adds a handler for event messages. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the subscription.

func WithPublishTimeout

func WithPublishTimeout(timeout time.Duration) Option

WithPublishTimeout is an option that sets the timeout for publishing a message. If the timeout is exceeded, the publish will fail.

func WithServiceHandler

func WithServiceHandler(service string, handler wrpkit.Handler, cancel ...*CancelFunc) Option

WithServiceHandler is an option that adds a handler for service messages. If the optional cancel parameter is provided, it will be set to a function that can be used to cancel the subscription.

type PubSub

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

PubSub is a struct representing a publish-subscribe system focusing on wrp messages.

func New

func New(self wrp.DeviceID, opts ...Option) (*PubSub, error)

New creates a new instance of the PubSub struct. The self parameter is the device id of the device that is creating the PubSub instance. During publishing, messages will be sent to the appropriate listeners based on the service in the message and the device id of the PubSub instance.

func (*PubSub) HandleWrp

func (ps *PubSub) HandleWrp(msg wrp.Message) error

HandleWrp publishes a wrp message to the appropriate listeners and returns if there was at least one handler that accepted the message. The error wrpkit.ErrNotHandled is returned if no listeners were found for the message.

func (*PubSub) SubscribeEgress

func (ps *PubSub) SubscribeEgress(h wrpkit.Handler) (CancelFunc, error)

SubscribeEgress subscribes to the egress route. The listener will be called when a message targets something other than this device. The returned CancelFunc may be called to remove the listener and cancel any future events sent to that listener.

func (*PubSub) SubscribeEvent

func (ps *PubSub) SubscribeEvent(event string, h wrpkit.Handler) (CancelFunc, error)

SubscribeEvent subscribes to the specified event. The listener will be called when a message matches the event. An event value of '*' may be used to match any event. The returned CancelFunc may be called to remove the listener and cancel any future events sent to that listener.

func (*PubSub) SubscribeService

func (ps *PubSub) SubscribeService(service string, h wrpkit.Handler) (CancelFunc, error)

SubscribeService subscribes to the specified service. The listener will be called when a message matches the service. A service value of '*' may be used to match any service. The returned CancelFunc may be called to remove the listener and cancel any future events sent to that listener.

Jump to

Keyboard shortcuts

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