ArvoEventRouter manages event routing and execution within the Arvo event system. It directs incoming events to appropriate handlers based on event type while maintaining telemetry and error handling.

The router enforces contract validation, manages execution costs, and provides comprehensive telemetry via OpenTelemetry integration. It handles event lifecycle management from initial receipt through processing and response generation.

const router = createArvoEventRouter({
source: "payment.service",
executionunits: 1,
handlers: [paymentProcessedHandler, paymentFailedHandler]
});

// Route an incoming event
const results = await router.execute(incomingEvent);

Hierarchy (view full)

Constructors

Properties

executionunits: number

Computational cost metric for router operations. Used for resource tracking and billing calculations.

handlersMap: Record<string, ArvoEventHandler<ArvoContract<string, string, Record<`${number}.${number}.${number}`, {
    accepts: ZodTypeAny;
    emits: Record<string, ZodTypeAny>;
}>, Record<string, any>>>> = {}

Registry mapping event types to their handlers

source: string

Source identifier for the router used in event routing

spanOptions: SpanOptions

The OpenTelemetry span options

Accessors

  • get systemErrorSchema(): {
        schema: ZodObject<{
            errorMessage: ZodString;
            errorName: ZodString;
            errorStack: ZodNullable<ZodString>;
        }, "strip", ZodTypeAny, {
            errorMessage: string;
            errorName: string;
            errorStack: null | string;
        }, {
            errorMessage: string;
            errorName: string;
            errorStack: null | string;
        }>;
        type: string;
    }
  • System error schema configuration. Error events follow format: sys..error

    Returns {
        schema: ZodObject<{
            errorMessage: ZodString;
            errorName: ZodString;
            errorStack: ZodNullable<ZodString>;
        }, "strip", ZodTypeAny, {
            errorMessage: string;
            errorName: string;
            errorStack: null | string;
        }, {
            errorMessage: string;
            errorName: string;
            errorStack: null | string;
        }>;
        type: string;
    }

    • schema: ZodObject<{
          errorMessage: ZodString;
          errorName: ZodString;
          errorStack: ZodNullable<ZodString>;
      }, "strip", ZodTypeAny, {
          errorMessage: string;
          errorName: string;
          errorStack: null | string;
      }, {
          errorMessage: string;
          errorName: string;
          errorStack: null | string;
      }>
    • type: string

Methods

  • Routes and executes an event through its appropriate handler. Creates a telemetry span, validates the event destination, finds a matching handler, and processes the event. Handles routing errors, missing handlers, and execution failures by returning error events with telemetry context. Tracks performance through execution units and span propagation.

    Parameters

    • event: ArvoEvent<Record<string, any>, Record<string,
          | null
          | string
          | number
          | boolean>, string>

      The event to be routed and processed

    • opentelemetry: ArvoEventHandlerOpenTelemetryOptions = ...

      Configuration for telemetry context inheritance

    Returns Promise<{
        events: ArvoEvent<Record<string, any>, Record<string,
            | null
            | string
            | number
            | boolean>, string>[];
    }>

    Promise resolving to resulting events or error events

    When event destination does not match router's source

    When no registered handler exists for the event type

    Other Violation error which are thrown by the registered event handlers