ArvoEventRouter is a TypeScript class designed to route ArvoEvents to appropriate event handlers. It provides a centralized mechanism for managing and executing multiple event handlers based on event types.
1. Centralized Event Processing Use ArvoEventRouter as a central point for processing various types of events in your application. This is particularly useful in microservices architectures or event-driven systems where different event handlers are bundled into one service
2. Event Transformation Pipeline Create a pipeline of event transformations by chaining multiple routers, each responsible for a specific stage of event processing.
const stage1Router = new ArvoEventRouter({
/* config */
});
const stage2Router = new ArvoEventRouter({
/* config */
});
const stage1Results = await stage1Router.execute(initialEvent);
const finalResults = await stage2Router.execute(stage1Results[0]);
import {
createArvoEventRouter,
createArvoEventHandler,
} from 'arvo-event-handler';
import { createArvoEvent } from 'arvo-core';
// Create event handlers
const handler1 = createArvoEventHandler(/* ... */);
const handler2 = createArvoEventHandler(/* ... */);
// Initialize the router
const router = createArvoEventRouter({
handlers: [handler1, handler2],
source: 'my.service.router',
executionunits: 10,
});
// Create an event
const event = createArvoEvent({
to: 'my.service.router',
type: 'my.event.type',
// ... other event properties
});
// Execute the router
const results = await router.execute(event);
console.log('Router results:', results);
executionunits
parameter can be used to track computational costs.traceparent
and tracestate
fields.For more detailed information, refer to the inline documentation in the source code.
See the MermaidMD diagram here