function causedBy
Since 0.6.0
causedBy(envelope: IntegrationEventEnvelope): { correlationId: string; causationId: string; }

Derives the causal metadata a consumed envelope contributes to the event its handling publishes next — the whole of the chain-root rule, extracted so no handler copies it by hand.

Examples

Example 1

import { causedBy, publishIntegrationEvent } from '@setu-ts/messaging-plugin';

await publishIntegrationEvent(runtime, broker, orderCharged, { orderId: '1' }, {
  ...causedBy(envelope),
});

Parameters

The envelope being handled

Return Type

{ correlationId: string; causationId: string; }

Metadata shaped to spread straight into publishIntegrationEvent: the consumed envelope's correlationId (falling back to its own id — the chain-root rule) and its id as the direct cause

Usage

import { causedBy } from "messaging-plugin/src/index.ts";