pubsub

package
v0.72.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CtxKeyNamespaceOverride ctxKey = "pubsub_ns_override"

CtxKeyNamespaceOverride is the context key used to override namespace per pubsub call

Variables

View Source
var Logf = func(format string, args ...interface{}) { _ = fmt.Sprintf(format, args...) }

Logf is a package-level logger function used by pubsub internals. By default it is a no-op to avoid polluting stdout; applications can assign it (e.g., to a UI-backed logger) to surface logs as needed.

Functions

func SetLogFunc

func SetLogFunc(f func(string, ...interface{}))

SetLogFunc allows applications to provide a custom logger sink.

func WithNamespace

func WithNamespace(ctx context.Context, ns string) context.Context

WithNamespace returns a new context that carries a pubsub namespace override

Types

type ClientAdapter

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

ClientAdapter adapts the pubsub Manager to work with the existing client interface

func NewClientAdapter

func NewClientAdapter(ps *pubsub.PubSub, namespace string) *ClientAdapter

NewClientAdapter creates a new adapter for the pubsub manager

func (*ClientAdapter) Close

func (a *ClientAdapter) Close() error

Close closes all subscriptions and topics

func (*ClientAdapter) ListTopics

func (a *ClientAdapter) ListTopics(ctx context.Context) ([]string, error)

ListTopics returns all subscribed topics

func (*ClientAdapter) Publish

func (a *ClientAdapter) Publish(ctx context.Context, topic string, data []byte) error

Publish publishes a message to a topic

func (*ClientAdapter) Subscribe

func (a *ClientAdapter) Subscribe(ctx context.Context, topic string, handler MessageHandler) error

Subscribe subscribes to a topic

func (*ClientAdapter) Unsubscribe

func (a *ClientAdapter) Unsubscribe(ctx context.Context, topic string) error

Unsubscribe unsubscribes from a topic

type HandlerID added in v0.52.14

type HandlerID string

HandlerID uniquely identifies a handler registration. Each call to Subscribe generates a new HandlerID, allowing multiple subscribers to the same topic with independent lifecycles. Unsubscribe operations are ref-counted per topic.

type Manager

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

Manager handles pub/sub operations

func NewManager

func NewManager(ps *pubsub.PubSub, namespace string) *Manager

NewManager creates a new pubsub manager

func (*Manager) Close

func (m *Manager) Close() error

Close closes all subscriptions and topics

func (*Manager) ListTopics

func (m *Manager) ListTopics(ctx context.Context) ([]string, error)

ListTopics returns all subscribed topics

func (*Manager) Publish

func (m *Manager) Publish(ctx context.Context, topic string, data []byte) error

Publish publishes a message to a topic

func (*Manager) Subscribe

func (m *Manager) Subscribe(ctx context.Context, topic string, handler MessageHandler) error

Subscribe subscribes to a topic with a handler. Returns a HandlerID that can be used to unsubscribe this specific handler. Multiple handlers can subscribe to the same topic.

func (*Manager) Unsubscribe

func (m *Manager) Unsubscribe(ctx context.Context, topic string) error

Unsubscribe decrements the subscription refcount for a topic. The subscription is only truly cancelled when refcount reaches zero. This allows multiple subscribers to the same topic.

type MessageHandler

type MessageHandler func(topic string, data []byte) error

MessageHandler represents a message handler function signature. Each handler is called when a message arrives on a subscribed topic. Multiple handlers can be registered for the same topic, and each will receive a copy of the message. Handlers should return an error only for critical failures; the error is logged but does not stop other handlers. This matches the client.MessageHandler type to avoid circular imports.

Jump to

Keyboard shortcuts

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