pubsub

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker is used to interact with the pubsub architecture

func NewBroker

func NewBroker() *Broker

NewBroker constructs a new Broker

func (*Broker) AddSubscriber

func (broker *Broker) AddSubscriber() *Subscriber

AddSubscriber adds a new subscriber to the subscriber pool and returns its reference

func (*Broker) Publish

func (broker *Broker) Publish(monitor string, message string)

Publish publishes messages flagged with a given monitor to the pubsub architecture

func (*Broker) Subscribe

func (broker *Broker) Subscribe(subscriber *Subscriber, monitor string)

Subscribe can add a monitor to a given subscriber

func (*Broker) Unsubscribe

func (broker *Broker) Unsubscribe(subscriber *Subscriber, monitor string)

Unsubscribe removes a monitor from a given subscriber

type Listener

type Listener func(*Message)

type Message

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

Message is used to model pubsub messages

func NewMessage

func NewMessage(message string, monitor string) *Message

NewMessage constructs a new message

func (*Message) GetMessageBody

func (message *Message) GetMessageBody() string

GetMessageBody returns the body of the message

func (*Message) GetMonitor

func (message *Message) GetMonitor() string

GetMonitor gives back the name of the monitor the message was flagged with

type Subscriber

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

Subscriber can listen to different monitors on a broker. Its messages channel will be updated whenever a new message is published with the associated broker.

func (*Subscriber) Destruct

func (subscriber *Subscriber) Destruct()

Destruct destructs a Subscriber

func (*Subscriber) GetMonitors

func (subscriber *Subscriber) GetMonitors() []string

GetMonitors returns a slice of all monitors the Subscriber is subscribed to.

func (*Subscriber) Listen

func (subscriber *Subscriber) Listen(listener Listener)

Listen listens for messages on the messages channel and calls a Listener function with the message as an argument.

type Subscribers

type Subscribers map[string]*Subscriber

Jump to

Keyboard shortcuts

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