/** * Defines the signature for the Callback that an EventSubscription should have. * * @param eventPayload Optional: The payload received with the event. * @param eventName Optional: The name of the received event. */ export type EventReceivedCallback = (eventPayload?: any, eventName?: string) => void | Promise; /** * Contains information about a subscription on the EngineEventBus. * External services can use this information to manage their own subscriptions. */ export type Subscription = { /** * The Id under which the EngineEventBus has stored the Subscription. */ readonly id: string; /** * The name of the event for which the Subscription was created. */ readonly eventName: string; /** * If set to true, the Subscription will be destroyed after first receiving * the event. */ readonly onlyReceiveOnce: boolean; }; export type ExternalSubscription = { remove: () => Promise; }; /** * The Event Bus is used by the Engine to manage communications between the individual engine services, as well as all Flow Node Instances and Process Instances. * * By default, the Engine uses its own EventAggregator. * * You can replace it with your own, if you want to connect the engine to an external messagebus. */ export type EngineEventBus = { /** * Creates a new {@link Subscription} on the EventBus for the event with the given name. * The {@link Subscription} will remain active, until manually disposed through the {@link EngineEventBus.unsubscribe} method. * * @param eventName The name of the Event to subscribe to. * @param callback The callback to execute, when the event is received. * @returns A {@link Subscription} object. */ subscribe: (eventName: string, callback: EventReceivedCallback) => Subscription; /** * Creates a new {@link Subscription} on the EventBus for the event with the given name. * The {@link Subscription} is automatically disposed, after the event was received once. * * @param eventName The name of the Event to subscribe to. * @param callback The callback to execute, when the event is received. * @returns A {@link Subscription} object. */ subscribeOnce: (eventName: string, callback: EventReceivedCallback) => Subscription; /** * Publishes a given event on the EventBus. * Usually, this function returns as soon as the Event was published. * However, it is possible to wait for all Subscribers to acknowledge receiving the Event, by providing an "onAcknowledgement" Callback function. * * @param eventName The name of the Event to publish. * @param payload The payload to send with the Event. * @param onAcknowledgement Optional: The callback to call, after all Subscribers have acknowledged receiving the Event. * @param eventId Optional: The Event ID to use. */ publish: (eventName: string, payload?: Record, onAcknowledgement?: () => void, eventId?: string) => void; /** * Allows a Subscriber to acknowledge the receit of an Event with the given ID. * * @param eventId The ID of the Event to acknowledge. */ acknowledgeEvent: (eventId: string) => void; /** * Disposes the given Event Subscription. * * @param subscription The Subscription to dispose. */ unsubscribe: (subscription: Subscription) => void; }; export type ExternalEventBus = { subscribeToWorkQueue: (queueName: string, callback: Function) => Promise; subscribeToTopicWithRoutingKey: (topic: string, routingKey: string, callback: Function, oneTimeSubscription?: boolean) => Promise; subscribeToBroadcast: (topic: string, callback: Function, oneTimeSubscription?: boolean) => Promise; publishToWorkQueue: (queueName: string, payload: Record) => Promise; publishToTopicWithRoutingKey: (topic: string, routingKey: string, payload: Record) => Promise; publishToBroadcast: (topic: string, payload: Record) => Promise; };