Create an in-memory event bus implementation.
This is suitable for single-process applications or testing. For distributed systems, you would implement EventBusPort with a message broker like RabbitMQ, Kafka, or Redis Pub/Sub.
const eventBus = createInMemoryEventBus();eventBus.subscribe(UserRegistered, (payload) => { console.log(`User registered: ${payload.email}`);});await eventBus.publish(UserRegistered, { userId: "123", email: "test@example.com" }); Copy
const eventBus = createInMemoryEventBus();eventBus.subscribe(UserRegistered, (payload) => { console.log(`User registered: ${payload.email}`);});await eventBus.publish(UserRegistered, { userId: "123", email: "test@example.com" });
// With error handlingconst eventBus = createInMemoryEventBus({ onHandlerError: (error, eventName, payload) => { logger.error(`Event handler failed for ${eventName}`, { error, payload }); },}); Copy
// With error handlingconst eventBus = createInMemoryEventBus({ onHandlerError: (error, eventName, payload) => { logger.error(`Event handler failed for ${eventName}`, { error, payload }); },});
Create an in-memory event bus implementation.
This is suitable for single-process applications or testing. For distributed systems, you would implement EventBusPort with a message broker like RabbitMQ, Kafka, or Redis Pub/Sub.