Function createArvoEventHandler

Creates an instance of ArvoEventHandler for the specified versioned contract and handlers.

This function is the recommended entry point for defining stateless, contract-driven services in Arvo. It binds a contract to its versioned handler implementations, enforces type-safe validation using Zod, and supports multi-domain event broadcasting and OpenTelemetry observability out of the box.

See ArvoEventHandler for implementation details.

const handler = createArvoEventHandler({
contract: userContract,
executionunits: 1,
handler: {
'1.0.0': async ({ event, domain, span }) => {
if (domain.event !== domain.self) {
logToSpan({
level: 'WARN',
message: 'Domain mismatch detected'
}, span);
}

const result = await processUser(event.data);

return {
type: 'evt.user.created',
data: result,
to: 'com.notification.service',
};
},
'2.0.0': async ({ event, contract }) => {
// Handler logic for v2.0.0
}
}
});
  • Type Parameters

    • TContract extends ArvoContract<string, string, Record<`${number}.${number}.${number}`, {
          accepts: ZodTypeAny;
          emits: Record<string, ZodTypeAny>;
      }>, Record<string, any>>

    Parameters

    • param: ArvoEventHandlerParam<TContract>

      Configuration object containing contract, versioned handlers, execution units, and span settings

    Returns ArvoEventHandler<TContract>

    A fully configured ArvoEventHandler instance for the given contract