msgbus

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNilSubChannel = Error("Uninitialised subscriber channel")
	ErrGeneratingKey = Error("Error generating key")
)

ErrNilSubChannel represents an error occurring when a subscriber channel is uninitialized. ErrGeneratingKey represents an error that occurs while generating a key.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error represents a textual error value that implements the error interface.

func (Error) Error

func (e Error) Error() string

Error returns the string representation of the Error type. It satisfies the error interface.

type MessageHandler

type MessageHandler[T any] chan TopicMessage[T]

MessageHandler is a channel used to handle incoming TopicMessage objects for a specific subscription. It allows processing messages in a concurrent manner.

type Publisher

type Publisher[T any] interface {
	Publish(msg TopicMessage[T])
}

Publisher is an interface for publishing messages to a specified topic. It provides the `Publish` method, which accepts a `TopicMessage` for delivery. Typically used in messaging systems to distribute messages across subscribers.

type PublisherSubscriber

type PublisherSubscriber[T any] interface {
	Publisher[T]
	Subscriber[T]
	Unsubscriber
}

PublisherSubscriber is an interface that combines publishing, subscribing, and unsubscribing functionalities for a message-bus system.

func NewMessageBus

func NewMessageBus[T any]() PublisherSubscriber[T]

NewMessageBus creates and initialises a new instance of a message bus implementing the PublisherSubscriber interface.

type Subscriber

type Subscriber[T any] interface {
	Subscribe(topic Topic, handler MessageHandler[T]) (uuid.UUID, error)
}

Subscriber defines behaviour for consuming messages from specific topics with unique handlers. The Subscribe method registers a handler for a topic and returns a unique identifier or an error.

type Topic

type Topic string

Topic represents a category or channel for messages in a publish-subscribe system.

type TopicMessage

type TopicMessage[T any] struct {
	Topic   Topic
	Message T
}

TopicMessage represents a message linked to a specific topic within a pub/sub system or message bus. The Topic field defines the subject, and Message holds the message payload as a byte slice.

type Unsubscriber

type Unsubscriber interface {
	Unsubscribe(topic Topic, key uuid.UUID)
}

Unsubscriber defines an interface for removing a subscription from a specified topic using a unique identifier.

Jump to

Keyboard shortcuts

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