broker

package
v0.0.0-...-6c83ee0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotReply = errors.New("cannot reply")
View Source
var ErrDisconnected = errors.New("disconnected from the broker")

ErrDisconnected occurs when trying to do something that requires a connection but one was unavailable

View Source
var Rcv = make(chan Message)

Functions

func Decode

func Decode(data []byte, result interface{}) error

func Encode

func Encode(data interface{}) ([]byte, error)

Types

type Broker

type Broker interface {
	Publish(ctx context.Context, event string, data interface{}) error
	Subscribe(ctx context.Context, events []string, messages chan<- Message) error
}

Broker is an interface describing message brokers

type IOPacket

type IOPacket struct {
	E string      `codec:"event"`
	D interface{} `codec:"data"`
}

IOPacket represents a JSON packet transmitted through an RW broker

func (*IOPacket) Ack

func (p *IOPacket) Ack(context.Context) error

func (*IOPacket) Body

func (p *IOPacket) Body() interface{}

func (*IOPacket) Event

func (p *IOPacket) Event() string

func (*IOPacket) Reply

func (p *IOPacket) Reply(ctx context.Context, data interface{}) error

type Message

type Message interface {
	Event() string
	Body() interface{}
	Reply(ctx context.Context, data interface{}) error
	Ack(ctx context.Context) error
}

type RWBroker

type RWBroker struct {
	R io.Reader
	W io.Writer
}

RWBroker is a broker that uses a Go Reader and Writer

func (*RWBroker) Publish

func (b *RWBroker) Publish(ctx context.Context, event string, data interface{}) error

Publish writes data to the writer

func (*RWBroker) Subscribe

func (b *RWBroker) Subscribe(ctx context.Context, events []string, messages chan<- Message) (err error)

Subscribe implements Broker interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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