eventbus

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0, Apache-2.0 Imports: 3 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 {
	StreamMap map[string]observer.Property
	// contains filtered or unexported fields
}

Broker holds maps of topics.

var (
	// DefaultBrooker is a system wide Broker. To easily help developer use the event bus straight away.
	DefaultBrooker *Broker
)

func NewBroker

func NewBroker() *Broker

NewBroker creates new broker. If you don't need a specific broker, you can use the already created DefaultBroker

func (*Broker) GetPublisher

func (b *Broker) GetPublisher(topic string) *Publisher

GetPublisher will obtain a Publisher dedicated for this broker and topic

func (*Broker) GetSubscriber

func (b *Broker) GetSubscriber(topic string, Handle func(i interface{}) error) *Subscriber

GetSubscriber will obtain Subscriber dedicated for this broker and topic with a handler function that will handle the message that it's received. In the Handle function, implementation MUST check for nil argument.

type Publisher

type Publisher struct {
	Topic  string
	Broker *Broker
}

Publisher is the publishing object. It automatically assigned with its broker and topic

func (*Publisher) Publish

func (p *Publisher) Publish(data interface{})

Publish a message into its broker on its assigned topic.

type Subscriber

type Subscriber struct {
	// Topic that subscribed.
	Topic string
	// Handle function that will be called if a message is published under this topic
	Handle func(i interface{}) error
	// Broker that this subscriber assigned to
	Broker *Broker
	// contains filtered or unexported fields
}

Subscriber the subscriber of a broker. This subscriber already asigned with topic it should subscribe.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe()

Subscribe will attach this subscriber to its broker. Subscriber are not automaticaly attached when you get it from a broker. Until you call this function, this subscriber will not receive any message.

func (*Subscriber) Unsubscribe

func (s *Subscriber) Unsubscribe()

Unsubscribe will detach this subscriber from its broker.

Jump to

Keyboard shortcuts

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