Documentation
¶
Overview ¶
Package eventbus is the domain-event bus riding the asynq message queue (ADR-001 step-6 preparation). Producers append events to the outbox inside their domain transaction; the publish pump hands unpublished events to the broker and marks them published on successful enqueue; the queue worker delivers each event to every subscriber of its topic, with the broker owning retries, backoff and the dead-letter archive. Delivery is at-least-once and subscribers are expected to be idempotent (the inbox pattern). Replacing asynq with another broker changes only the Publisher adapter and the worker shell.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus routes outbox events to subscribers by topic.
func New ¶
func New(outboxRepo repository.OutboxRepo, publisher Publisher) *Bus
func (*Bus) Deliver ¶
Deliver runs every subscriber of the event's topic; the queue worker calls it once per delivery task. The first failing subscriber fails the task so the broker retries the whole event — subscribers that already succeeded re-run and skip via their inbox markers.
func (*Bus) Publish ¶
Publish drains up to limit unpublished outbox events onto the broker, marking each published once its enqueue succeeded. A failing enqueue stops the tick so events enter the broker in outbox order; ordering between deliveries is then the broker's (concurrent workers), which subscribers already tolerate via their per-key serialization and inbox markers. Events whose topic has no subscribers are marked published without an enqueue so an orphaned topic cannot wedge the pump.
func (*Bus) Subscribe ¶
Subscribe registers a consumer for a topic. The consumer name is the subscriber's identity for logging and mirrors the inbox consumer it uses for idempotency. Registration happens at composition time, before publishing and delivery start; Subscribe is not safe for concurrent use with them.
type Handler ¶
Handler processes one event. Returning an error fails the delivery task so the broker retries it; handlers must therefore be idempotent.