createListener Method

Create a listener for long polling events from a GlobalEventSubscription. When event is received from the subscription, every registered listener callback is called. This continuously waits for events until all created listeners for that subscriptionInstanceId are deleted. GlobalEventSAS token expirations are handled automatically, AccessToken expiration is handled by calling authenticationCallback to get a new token.

createListener(requestContext: AuthorizedClientRequestContext, authenticationCallback: () => Promise<AccessToken>, subscriptionInstanceId: string, listener: (event: IModelHubGlobalEvent) => void): () => void

throws IModelHubClientError with IModelHubStatus.UndefinedArgumentError or IModelHubStatus.InvalidArgumentError if one of the arguments is undefined or has an invalid value.

Parameter Type Description
requestContext AuthorizedClientRequestContext  
authenticationCallback () => Promise<AccessToken> Callback used to get AccessToken. Only the first registered authenticationCallback for this subscriptionId will be used.
subscriptionInstanceId string Id of GlobalEventSubscription.
listener (event: IModelHubGlobalEvent) => void Callback that is called when an IModelHubGlobalEvent is received.

Returns - Function that deletes the created listener.

Defined in

Last Updated: 08 January, 2020