createListener Method

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

createListener(requestContext: ClientRequestContext, authenticationCallback: () => Promise<AccessToken>, subscriptionId: string, iModelId: GuidString, listener: (event: IModelHubEvent) => 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 ClientRequestContext The client request context
authenticationCallback () => Promise<AccessToken> Callback used to get AccessToken. Only the first registered authenticationCallback for this subscriptionId will be used.
subscriptionId string Id of EventSubscription.
iModelId GuidString Id of the iModel. See HubIModel.
listener (event: IModelHubEvent) => void Callback that is called when an IModelHubEvent is received.

Returns - Function that deletes the created listener.

Defined in

Last Updated: 08 January, 2020