2.2 KiB
2.2 KiB
Story 5.2: Event Bus System
Metadata
- Story ID: 5.2
- Title: Event Bus System
- Epic: 5 - Infrastructure Adapters
- Status: Pending
- Priority: High
- Estimated Time: 6-8 hours
- Dependencies: 1.1
Goal
Implement a complete event bus system supporting both in-process (for development/testing) and Kafka (for production) with publish/subscribe capabilities.
Description
This story implements an event bus that allows modules to publish and subscribe to events. It supports both in-process channels for development and Kafka for production, with a clean interface that makes the implementation swappable.
Deliverables
1. Event Bus Interface (pkg/eventbus/eventbus.go)
EventBusinterface with:Publish(ctx context.Context, topic string, event Event) errorSubscribe(topic string, handler EventHandler) errorUnsubscribe(topic string) error
EventandEventHandlertypes
2. In-Process Bus (internal/infra/bus/inprocess_bus.go)
- Channel-based in-process bus
- Used for testing and development
- Thread-safe implementation
3. Kafka Bus (internal/infra/bus/kafka_bus.go)
- Kafka producer for publishing
- Consumer groups for subscribing
- Error handling and retries
- Connection management
4. Core Events
- Define core platform events:
platform.user.createdplatform.user.updatedplatform.role.assignedplatform.permission.granted
5. Configuration
- Kafka config in
config/default.yaml - Bus selection (in-process vs Kafka)
6. DI Integration
- Provider function for EventBus
- Register in DI container
- Switchable via config
Acceptance Criteria
- Event bus interface is defined
- In-process bus works for development
- Kafka bus works for production
- Events can be published and subscribed
- Bus is swappable via config
- Error handling works correctly
- Core events are defined
Files to Create/Modify
pkg/eventbus/eventbus.go- Event bus interfaceinternal/infra/bus/inprocess_bus.go- In-process implementationinternal/infra/bus/kafka_bus.go- Kafka implementationinternal/di/providers.go- Add event bus providerconfig/default.yaml- Add Kafka config