eventbus

package
v0.0.0-...-252e742 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShutdownSystem

func ShutdownSystem()

ShutdownSystem shuts down the system bus and clears the singleton.

After calling ShutdownSystem, the application may call InitSystem again to create a new system bus instance.

func ShutdownUser

func ShutdownUser()

ShutdownUser shuts down the user bus and clears the singleton.

After calling ShutdownUser, the application may call InitUser again to create a new user bus instance.

Types

type EventBus

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

EventBus is a Redis Pub/Sub based event bus with a namespace.

It matches the TypeScript EventBusRedis behaviour:

  • Events are published as a JSON array of positional arguments.
  • Subscribers register handlers locally and the bus manages Redis subscriptions idempotently.
  • The namespace determines the Redis channel prefix.

func InitSystem

func InitSystem(ctx context.Context) *EventBus

InitSystem creates and starts the internal/system event bus.

This bus is used for cross-instance synchronisation and internal component communication. It must be called during RedisSMQ bootstrap.

It is safe to call InitSystem multiple times. If the system bus was previously shut down, InitSystem will create and start a new instance.

func InitUser

func InitUser(ctx context.Context) *EventBus

InitUser creates and starts the public/user event bus.

Unlike the system bus, the user bus is not started automatically during RedisSMQ bootstrap. Applications that need to expose events to external subscribers must call InitUser explicitly.

If the user bus was previously shut down, calling InitUser again will create and start a fresh instance.

func NewEventBus

func NewEventBus(namespace string) *EventBus

NewEventBus creates a new event bus instance with the given namespace.

The namespace is used to build the Redis channel prefix:

redis-smq:events:{namespace}:*

The Redis client must already be initialized before calling NewEventBus.

func System

func System() *EventBus

System returns the internal/system event bus singleton.

It panics if InitSystem has not been called or if the system bus has been shut down.

func User

func User() *EventBus

User returns the public/user event bus singleton.

It returns nil if the user bus has not been initialised.

func (*EventBus) IsRunning

func (eb *EventBus) IsRunning() bool

IsRunning reports whether the event bus is currently running.

func (*EventBus) Publish

func (eb *EventBus) Publish(ctx context.Context, eventName string, args ...interface{}) error

Publish publishes an event to Redis.

The supplied arguments are serialized as a JSON array, matching the TypeScript wire format.

func (*EventBus) Shutdown

func (eb *EventBus) Shutdown()

Shutdown gracefully stops the event bus and releases Redis subscriptions. It is safe to call multiple times.

func (*EventBus) Start

func (eb *EventBus) Start(ctx context.Context)

Start initializes the event bus and begins listening for Redis messages. It is safe to call multiple times; subsequent calls are no-ops.

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(handler Handler, eventNames ...string) (*Subscription, error)

Subscribe registers a handler for one or more event names.

It returns a Subscription that can be used to unsubscribe from all the specified events at once.

type Handler

type Handler func(eventName string, args []interface{})

Handler is the callback signature for event bus subscriptions. It receives the original event name (without the namespace prefix) and the positional arguments decoded from the JSON array payload.

type Subscription

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

Subscription represents a registered event handler.

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

Unsubscribe removes this subscription and stops receiving events.

Jump to

Keyboard shortcuts

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