Documentation
¶
Index ¶
- func ShutdownSystem()
- func ShutdownUser()
- type EventBus
- func (eb *EventBus) IsRunning() bool
- func (eb *EventBus) Publish(ctx context.Context, eventName string, args ...interface{}) error
- func (eb *EventBus) Shutdown()
- func (eb *EventBus) Start(ctx context.Context)
- func (eb *EventBus) Subscribe(handler Handler, eventNames ...string) (*Subscription, error)
- type Handler
- type Subscription
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 ¶
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 ¶
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 ¶
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) Publish ¶
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.
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.