bus

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WithChunkLimits added in v0.12.0

func WithChunkLimits(ctx context.Context, limits ChunkLimits) context.Context

WithChunkLimits returns a context that carries the requester's chunk caps to a StreamListener.

Types

type Broadcaster added in v0.5.0

type Broadcaster interface {
	Broadcast(timeout time.Duration, 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(ctx context.Context, 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 ChunkLimits added in v0.12.0

type ChunkLimits struct {
	MaxBytes uint64
	MaxRows  uint32
}

ChunkLimits are the caps a requester asks a StreamListener to apply to one chunk. A zero field means the listener's default.

func ChunkLimitsFrom added in v0.12.0

func ChunkLimitsFrom(ctx context.Context) ChunkLimits

ChunkLimitsFrom returns the chunk caps the requester sent, or the zero value.

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 NewBatchMessageWithNode added in v0.6.0

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

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

func NewBatchMessageWithNodeAndGroup added in v0.11.0

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

NewBatchMessageWithNodeAndGroup returns a new batch Message carrying an explicit business group. Use it for pre-marshaled ([]byte) payloads whose group is embedded in the opaque body and therefore not recoverable by the publisher metrics path.

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 NewMessageWithNodeAndGroup added in v0.11.0

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

NewMessageWithNodeAndGroup returns a new Message carrying an explicit business group. Use it for pre-marshaled ([]byte) payloads (e.g. secondary-index sync), where the group is embedded in the opaque body and therefore not recoverable by the publisher metrics path.

func NewMessageWithNodeSelectors added in v0.8.0

func NewMessageWithNodeSelectors(id MessageID, nodeSelectors map[string][]string, timeRange *modelv1.TimeRange, data interface{}) Message

NewMessageWithNodeSelectors returns a new Message with a MessageID and NodeSelectors and embed data. Nodes matching any of the selectors will receive the message.

func NewMessageWithSelectorsAndGroup added in v0.12.0

func NewMessageWithSelectorsAndGroup(id MessageID, selectors map[string][]string, timeRange *modelv1.TimeRange, group string, data interface{}) Message

NewMessageWithSelectorsAndGroup retains routing and admission identity for opaque requests.

func (Message) BatchModeEnabled added in v0.6.0

func (m Message) BatchModeEnabled() bool

BatchModeEnabled returns whether the Message is sent in batch mode.

func (Message) Data

func (m Message) Data() interface{}

Data returns the data wrapped in the Message.

func (Message) Group added in v0.11.0

func (m Message) Group() string

Group returns the business group the Message belongs to. It is set for pre-marshaled ([]byte) payloads whose group cannot be recovered from the body, so the queue metrics can still be labeled by group.

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.

func (Message) NodeSelectors added in v0.8.0

func (m Message) NodeSelectors() map[string][]string

NodeSelectors returns the node selectors of the Message.

func (Message) TimeRange added in v0.8.0

func (m Message) TimeRange() *modelv1.TimeRange

TimeRange returns the time range of the Message.

type MessageID

type MessageID uint64

MessageID the identity of a Message.

type MessageListener

type MessageListener interface {
	Rev(ctx context.Context, message Message) Message
	CheckHealth() *common.Error
}

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

type NodeStream added in v0.12.0

type NodeStream interface {
	Node() string
	Next(ctx context.Context) (Message, error)
	Close()
}

NodeStream is one node's chunk sequence. Next returns io.EOF after the last chunk. A transport or remote error is terminal and never io.EOF. Close cancels the node's scan and is safe to call more than once.

type Publisher

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

Publisher allow sending Messages to a Topic.

type ScatterOptions added in v0.12.0

type ScatterOptions struct {
	// Prefetch is the depth of the per-stream buffer of received chunks.
	Prefetch int
	// IdleTimeout fails a node stream that delivers neither a chunk nor a heartbeat for this long.
	IdleTimeout time.Duration
	// MaxChunkBytes is the cap for one chunk body, forwarded to the data node.
	MaxChunkBytes uint64
	// MaxChunkRows is the cap for the rows of one chunk, forwarded to the data node.
	MaxChunkRows uint32
}

ScatterOptions tunes the node streams opened by Scatterer.Scatter. A zero field selects the implementation default.

type Scatterer added in v0.12.0

type Scatterer interface {
	Scatter(ctx context.Context, topic Topic, message Message, opts ScatterOptions) ([]NodeStream, error)
}

Scatterer opens one server-streaming scan per node that matches the message's node selectors and returns the streams without reading them. The streams live as long as ctx; canceling it ends every stream.

type Sink added in v0.12.0

type Sink interface {
	Send(ctx context.Context, chunk Message) error
}

Sink receives the chunks a StreamListener emits. Send blocks while the requester applies backpressure and returns ctx.Err() when the requester is gone.

type StreamListener added in v0.12.0

type StreamListener interface {
	CheckHealth() *common.Error
	RevStream(ctx context.Context, message Message, sink Sink) error
}

StreamListener handles one message by emitting zero or more chunks. Returning nil ends the stream cleanly; returning an error ends it with that error.

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.

type UnImplementedHealthyListener added in v0.8.0

type UnImplementedHealthyListener struct{}

UnImplementedHealthyListener is a listener that is not implemented. But it is healthy.

func (*UnImplementedHealthyListener) CheckHealth added in v0.8.0

func (h *UnImplementedHealthyListener) CheckHealth() *common.Error

CheckHealth always returns nil.

func (*UnImplementedHealthyListener) Rev added in v0.8.0

Rev always panics.

Jump to

Keyboard shortcuts

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