onIntegrationEvent<T>(definition: IntegrationEventDefinition<T>,handler: IntegrationEventHandler<T>,options?: SubscribeOptions): 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.
definition: IntegrationEventDefinition<T>
The contract being consumed
handler: IntegrationEventHandler<T>
The application handler
options: SubscribeOptions
Consumer-group configuration, forwarded unchanged to
broker.subscribe
The subscription definition to register