function onIntegrationEvent
Since 0.6.0
onIntegrationEvent<T>(): SubscriptionDefinition

Produces a SubscriptionDefinition for an integration-event contract — the declarative form, plugging straight into MessagingPlugin({ subscriptions }), or spread by hand into an imperative broker.subscribe after start().

The returned wrapper validates the delivered message against the definition, runs definition.parse, rebuilds the envelope with its data set to the parsed value, and only then invokes the application handler. A malformed envelope, a mismatched type/version, or a rejecting parser throws IntegrationEventRejectedError — the application handler is never called with an unvalidated value — and the rejection follows the broker's OWN failure path, which differs per arm and is not a retry guarantee: RabbitMQ nacks with requeue DISABLED (dead-lettered when a DLX is configured, discarded otherwise) and logs; NATS naks, which redelivers while the stream retains the message; the in-memory broker reports to onDispatchError and drops. Since a rejection here is deterministic — the same envelope fails the same way every time — redelivery cannot resolve it, so a dead-letter queue, not a retry, is the place to inspect one. When MessagingPlugin({ behaviors }) is configured, the behaviour chain runs BEFORE this wrapper, so IngressContext.payload is the raw envelope and never the parsed payload.

A handler needing a resolved capability uses the existing RegistryFactory<SubscriptionDefinition> arm of SubscriptionEntry: (services) => onIntegrationEvent(definition, handlerFor(services)) — no factory variant of this function exists, and none is needed.

Examples

Example 1

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

const app = createApplication({
  plugins: [
    MessagingPlugin({
      subscriptions: [
        onIntegrationEvent(orderPlaced, async (payload) => {
          await provisionOrder(payload.orderId);
        }),
      ],
    }),
  ],
});

Type Parameters

The event payload type

Parameters

The contract being consumed

The application handler

optional
options: SubscribeOptions

Consumer-group configuration, forwarded unchanged to broker.subscribe

Return Type

The subscription definition to register

Usage

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