Documentation ¶
Index ¶
- Variables
- type CancelFunc
- type Option
- func Normify(opts ...wrp.NormifierOption) Option
- func WithEgressHandler(handler wrpkit.Handler, cancel ...*CancelFunc) Option
- func WithEventHandler(event string, handler wrpkit.Handler, cancel ...*CancelFunc) Option
- func WithPublishTimeout(timeout time.Duration) Option
- func WithServiceHandler(service string, handler wrpkit.Handler, cancel ...*CancelFunc) Option
- type PubSub
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.