function publishIntegrationEvent
Since 0.6.0
publishIntegrationEvent<T>(
runtime: IRuntimeServices,
payload: T,
): Promise<void>

Publishes one integration event: builds the envelope from the caller's already-typed payload and hands it to broker.publish on the definition's topic.

The definition's parse function is deliberately NOT run here. parse is a narrowing function unknown → T, and a realistic one (a schema with defaults, coercion, or stripping) returns a different object than it was given — running it on publish would silently change what the producer asked to send. It also would not buy the guarantee it appears to: what the consumer parses is the value after a JSON round trip, which this call has not seen. The consequence is honest and documented: a producer CAN publish a payload its own consumers reject, and that surfaces at the consumer as a reason: 'parse' rejection.

Examples

Example 1

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

await publishIntegrationEvent(runtime, broker, orderPlaced, { orderId: '1' });

Type Parameters

The event payload type

Parameters

runtime: IRuntimeServices

Runtime services supplying uuid() and now()

The broker to publish through

The contract being published

payload: T

The event payload, carried verbatim

optional
metadata: IntegrationEventMetadata

Optional causal metadata

Return Type

Promise<void>

Throws

Whatever broker.publish rejects with, unchanged

Usage

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