Array of event handlers to register with the broker. Each handler is automatically subscribed to its source topic and executed when matching events are received. Supports ArvoResumable, ArvoOrchestrator, and ArvoEventHandler instances.
Optional
options: { Optional configuration for customizing broker behavior and event processing
Optional
onCallback for processing domain-specific events produced by handlers. Enables custom routing logic, external system integration, or domain-specific event processing patterns. Receives events grouped by domain (excluding 'all') and the broker instance for republishing.
Optional
onCustom error handler invoked when processing failures occur. Receives the error and triggering event for logging, monitoring, or recovery actions. Defaults to console.error with structured event information for debugging.
Configuration object containing the broker instance and event resolution function
Creates a local event broker configured with domain event handlers and provides event resolution capabilities
This factory function establishes a comprehensive event-driven architecture within a single process, automatically wiring event handlers to their source topics and providing sophisticated event propagation with domain-specific routing capabilities. The broker implements sequential queue-based processing with built-in error handling and observability features.
Core Architecture: The broker acts as an in-memory event bus that connects ArvoResumable orchestrators, ArvoOrchestrator state machines, and ArvoEventHandler services in a unified event-driven system. This enables local testing of distributed workflows and provides a foundation for event-driven microservices.
Event Processing Flow:
Throws
When event source conflicts with registered handler sources during resolution
Example
Basic Event-Driven Architecture Setup:
Example
Advanced Configuration with Domain Routing:
Example
Event Resolution for Integration Testing:
Example
Direct Event Publishing:
Remarks
Event Source Conflict Prevention: The resolve function validates that the input event's source doesn't conflict with registered handler sources to prevent infinite loops and routing ambiguity.
Sequential Processing Guarantee: Events are processed sequentially within each topic to maintain ordering guarantees and prevent race conditions in workflow state management.
Integration Testing Benefits: This pattern enables comprehensive integration testing of event-driven workflows without requiring external message brokers, making test suites faster and more reliable while maintaining production-like behavior patterns.