pubsub

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatMessage

func FormatMessage(streamType string, data string) []byte

Helper to format stream messages

Types

type Broker

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

Broker a simple in-memory pub/sub system.

func GetBroker

func GetBroker() *Broker

GetBroker returns the singleton instance of the Broker.

func (*Broker) CloseTopic

func (b *Broker) CloseTopic(topic string)

CloseTopic closes all subscriber channels and clears the cache for a given topic.

func (*Broker) Publish

func (b *Broker) Publish(topic string, msg []byte)

Publish publishes a message to all subscribers of a topic and caches it.

func (*Broker) Subscribe

func (b *Broker) Subscribe(topic string) (<-chan []byte, func())

Subscribe subscribes to a topic. It first sends all cached messages to the new subscriber, then adds the subscriber to receive live messages.

type WsMessage

type WsMessage struct {
	Stream string `json:"stream"`
	Data   string `json:"data"`
}

Jump to

Keyboard shortcuts

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