pkg

package
v0.0.0-...-434faa1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: Apache-2.0 Imports: 4 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 a message store and message distributer with a single topic. TODO: implement topics

func NewBroker

func NewBroker() *Broker

func (*Broker) Run

func (b *Broker) Run(ctx context.Context)

Run starts the broker. Run is a blocking call and should be started as goroutine.

func (*Broker) Send

func (b *Broker) Send(message string) error

Send is used by message publishers to add new messages on the broker.

func (*Broker) Subscribe

func (b *Broker) Subscribe(consumer Consumer)

Subscribe allows a Consumer to subscribe to the broker messages. The broker will be also issue a backfill of the consumer, sending it historical messages.

type Consumer

type Consumer interface {
	Receive(string)
}

Consumer is the interface for registering consumers at the broker. The broker will call the consumer's Receive method to forward messages from the broker.

type MyConsumer

type MyConsumer struct {
	Id string
}

MyConsumer is an example implementation of a Consumer.

func (*MyConsumer) Receive

func (c *MyConsumer) Receive(message string)

Receive implements the Consumer interface

type Producer

type Producer struct {
	// Broker is a reference to the broker where to publish new messages
	Broker *Broker
}

func (*Producer) Run

func (p *Producer) Run(ctx context.Context)

Run is the main event loop of a Producer. In this loop it watches for system changes and sends the corresponding events to the broker. Run is a blocking call and should be started as goroutine.

Jump to

Keyboard shortcuts

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