bus

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bus implements a message bus which is a common data model and a messaging infrastructure to allow different modules to communicate locally or remotely.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTopicNotExist hints the topic published doesn't exist.
	ErrTopicNotExist = errors.New("the topic does not exist")
)

Functions

This section is empty.

Types

type Broadcaster added in v0.5.0

type Broadcaster interface {
	Broadcast(topic Topic, message Message) ([]Future, error)
}

Broadcaster allow sending Messages to a Topic and receiving the responses.

type Bus

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

The Bus allows publish-subscribe-style communication between components.

func NewBus

func NewBus() *Bus

NewBus returns a Bus.

func (*Bus) Close added in v0.3.0

func (b *Bus) Close()

Close a Bus until all Messages are sent to Subscribers.

func (*Bus) Publish

func (b *Bus) Publish(topic Topic, message ...Message) (Future, error)

Publish sends Messages to a Topic.

func (*Bus) Subscribe

func (b *Bus) Subscribe(topic Topic, listener MessageListener) error

Subscribe adds an MessageListener to be called when a message of a Topic is posted.

type Future

type Future interface {
	Get() (Message, error)
	GetAll() ([]Message, error)
}

Future represents a future result of an asynchronous publishing.

type Message

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

Message is send on the bus to all subscribed listeners.

func NewMessage

func NewMessage(id MessageID, data interface{}) Message

NewMessage returns a new Message with a MessageID and embed data.

func NewMessageWithNode added in v0.5.0

func NewMessageWithNode(id MessageID, node string, data interface{}) Message

NewMessageWithNode returns a new Message with a MessageID and NodeID and embed data.

func (Message) Data

func (m Message) Data() interface{}

Data returns the data wrapped in the Message.

func (Message) ID

func (m Message) ID() MessageID

ID outputs the MessageID of the Message.

func (Message) Node added in v0.5.0

func (m Message) Node() string

Node returns the node name of the Message.

type MessageID

type MessageID uint64

MessageID the identity of a Message.

type MessageListener

type MessageListener interface {
	Rev(message Message) Message
}

MessageListener is the signature of functions that can handle an EventMessage.

type Publisher

type Publisher interface {
	Publish(topic Topic, message ...Message) (Future, error)
}

Publisher allow sending Messages to a Topic.

type Subscriber

type Subscriber interface {
	Subscribe(topic Topic, listener MessageListener) error
}

Subscriber allow subscribing a Topic's messages.

type Topic

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

Topic is the object which messages are sent to or received from.

func BiTopic

func BiTopic(id string) Topic

BiTopic returns bidirectional Topic.

func UniTopic

func UniTopic(id string) Topic

UniTopic returns an unary Topic.

func (Topic) String added in v0.5.0

func (t Topic) String() string

String returns the string representation of the Topic.

Jump to

Keyboard shortcuts

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