Invoke the APIs
The APIs previously discussed are Subscribe, SubscribeOnce, Publish, and Dispose.
Here's an overview of each:
Subscribe
This API can subscribe to an event from Service Center. Using this API, the external application can listen to the application or object level events from the Service Center. Once an event is subscribed to using this API, an external application is notified until the subscription is disposed.
subscribe: (payload: IEventSubscriptionPayload, callbackFunction: (response:IEventResponsePayload) => void)
=> ISubscriptionContext;
Parameter | Required? | Description |
---|---|---|
payload | Yes | Requests details for the subscription with with corresponding event name. |
SubscribeOnce
Use this API to subscribe to a Service Center event just once. Using this API, external applications can listen to the application or object level events from Service Center. This subscription is disposed automatically after the first notification.
The following code sample shows the syntax for SubscribeOnce:
subscribeOnce: (payload: IEventSubscriptionPayload, callbackFunction: (response: IEventResponsePayload) => void)
=> ISubscriptionContext;
Parameter | Required? | Description |
---|---|---|
payload | Yes | Requests details for the subscription with with corresponding event name. |
callbackFunction | Yes | A callback function, which receives calls whenever events are triggered within Service Center. |
Publish
This API can inform the Service Center to operate. The API returns a promise to which you can add a then-catch block. The block then returns the operation's status and any data returned after the process is completed.
publish: (payload: IOperationPublishPayload) => Promise<IOperationResponsePayload>;
Parameter | Required? | Description |
---|---|---|
payload | Yes | Requests details for the subscription with with corresponding operationName. |
Dispose
This API can dispose or unregister any subscriptions that's added for an event. By disposing the subscription, the API will not trigger any further notifications to the client side receiver.
dispose:() => void;