SubscriptionEventHandlers interface

Interface that describes the functions to be implemented by the user which are invoked by the EventHubConsumerClient when the subscribe() method is called to receive events from Event Hub.

Properties

processClose

The function invoked by EventHubConsumerClient each time the subscription stops reading events from a partition. The information on this partition will be available on the PartitionContext passed to the function processClose.

If the CloseReason passed to this function is OwnershipLost, then another subscription has taken over reading from the same partition using the same consumer group. This is expected if you have multiple instances of your application running and have passed the CheckpointStore to the client to load balance.

If the CloseReason is Shutdown, this indicates that either subscription.close() was called, or an error occured. Unless the subscription was explicitly closed via subscription.close(), the subscription will attempt to resume reading events from the last checkpoint for the partition.

processError

The function invoked by EventHubConsumerClient for errors that occur when receiving events or when executing any of the user provided functions passed to the subscribe() method.

The PartitionContext passed to this function will indicate the partition that was being processed when the error was thrown. In cases where an error is thrown outside of processing events from a partition(e.g. failure to perform load balancing), the partitionId on the context will be an empty string.

After the client completes executing this function, the partitionClose function is invoked.

processEvents

The function invoked by EventHubConsumerClient when a set of events is received. The PartitionContext passed to this function can be used to determine which partition is being read from.

The updateCheckpoint() method on the context can be used to update checkpoints in the CheckpointStore (if one was provided to the client). Use this in frequent intervals to mark events that have been processed so that the client can restart from such checkpoints in the event of a restart or error recovery.

Note: It is possible for received events to be an empty array. This can happen if there are no new events to receive in the maxWaitTimeInSeconds, which is defaulted to 60 seconds. The maxWaitTimeInSeconds can be changed by setting it in the options passed to subscribe().

processInitialize

The function invoked by EventHubConsumerClient each time the subscription is about to begin reading from a partition. The PartitionContext passed to this function can be used to determine which partition is about to be read from.

The client will start receiving events for the partition only after completing the execution of this function (if provided). Therefore, use this function to carry out any setup work including async tasks.

Property Details

processClose

The function invoked by EventHubConsumerClient each time the subscription stops reading events from a partition. The information on this partition will be available on the PartitionContext passed to the function processClose.

If the CloseReason passed to this function is OwnershipLost, then another subscription has taken over reading from the same partition using the same consumer group. This is expected if you have multiple instances of your application running and have passed the CheckpointStore to the client to load balance.

If the CloseReason is Shutdown, this indicates that either subscription.close() was called, or an error occured. Unless the subscription was explicitly closed via subscription.close(), the subscription will attempt to resume reading events from the last checkpoint for the partition.

processClose?: ProcessCloseHandler

Property Value

processError

The function invoked by EventHubConsumerClient for errors that occur when receiving events or when executing any of the user provided functions passed to the subscribe() method.

The PartitionContext passed to this function will indicate the partition that was being processed when the error was thrown. In cases where an error is thrown outside of processing events from a partition(e.g. failure to perform load balancing), the partitionId on the context will be an empty string.

After the client completes executing this function, the partitionClose function is invoked.

processError: ProcessErrorHandler

Property Value

processEvents

The function invoked by EventHubConsumerClient when a set of events is received. The PartitionContext passed to this function can be used to determine which partition is being read from.

The updateCheckpoint() method on the context can be used to update checkpoints in the CheckpointStore (if one was provided to the client). Use this in frequent intervals to mark events that have been processed so that the client can restart from such checkpoints in the event of a restart or error recovery.

Note: It is possible for received events to be an empty array. This can happen if there are no new events to receive in the maxWaitTimeInSeconds, which is defaulted to 60 seconds. The maxWaitTimeInSeconds can be changed by setting it in the options passed to subscribe().

processEvents: ProcessEventsHandler

Property Value

processInitialize

The function invoked by EventHubConsumerClient each time the subscription is about to begin reading from a partition. The PartitionContext passed to this function can be used to determine which partition is about to be read from.

The client will start receiving events for the partition only after completing the execution of this function (if provided). Therefore, use this function to carry out any setup work including async tasks.

processInitialize?: ProcessInitializeHandler

Property Value