Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventProcessor

Package version

Event Processor based applications consist of one or more instances of EventProcessor which have been configured to consume events from the same Event Hub and consumer group. They balance the workload across different instances by distributing the partitions to be processed among themselves. They also allow the user to track progress when events are processed using checkpoints.

A checkpoint is meant to represent the last successfully processed event by the user from a particular partition of a consumer group in an Event Hub instance.

You need the below to create an instance of EventProcessor

  • The name of the consumer group from which you want to process events
  • An instance of EventHubClient class that was created for the Event Hub instance.
  • A user implemented class that extends the PartitionProcessor class. To get started, you can use the base class PartitionProcessor which simply logs the incoming events. To provide your code to process incoming events, extend this class and override the processEvents() method. For example:
    class SamplePartitionProcessor extends PartitionProcessor {
      async processEvents(events) {
         // user code to process events here
         // Information on the partition being processed is available as properties on the `SamplePartitionProcessor` class
         // use `this.updateCheckpoint()` method to update checkpoints as needed
      }
    }
  • An instance of PartitionManager. To get started, you can pass an instance of InMemoryPartitionManager. For production, choose an implementation that will store checkpoints and partition ownership details to a durable store. Implementations of PartitionManager can be found on npm by searching for packages with the prefix @azure/eventhub-checkpointstore-.
class

EventProcessor

Hierarchy

  • EventProcessor

Index

Constructors

Accessors

Methods

Constructors

constructor

  • Parameters

    • consumerGroupName: string

      The name of the consumer group from which you want to process events.

    • eventHubClient: EventHubClient

      An instance of EventHubClient that was created for the Event Hub instance.

    • PartitionProcessorClass: PartitionProcessor

      A user-provided class that extends the PartitionProcessor class. This class will be responsible for processing and checkpointing events.

    • partitionManager: PartitionManager

      An instance of PartitionManager. To get started, you can pass an instance of InMemoryPartitionManager. For production, choose an implementation that will store checkpoints and partition ownership details to a durable store.

    • options: FullEventProcessorOptions

      A set of options to configure the Event Processor

      • maxBatchSize : The max size of the batch of events passed each time to user code for processing.
      • maxWaitTimeInSeconds : The maximum amount of time to wait to build up the requested message count before passing the data to user code for processing. If not provided, it defaults to 60 seconds.

    Returns EventProcessor

Accessors

id

  • get id(): string

Methods

isRunning

  • isRunning(): boolean

start

  • start(): void
  • Starts the EventProcessor. Based on the number of instances of EventProcessor that are running for the same consumer group, the partitions are distributed among these instances to process events.

    For each partition, the user provided PartitionProcessor is instantiated.

    Subsequent calls to start will be ignored if this event processor is already running. Calling start() after stop() is called will restart this event processor.

    Returns void

stop

  • stop(): Promise<void>
  • Stops processing events for all partitions owned by this event processor. All PartitionProcessor will be shutdown and any open resources will be closed.

    Subsequent calls to stop will be ignored if the event processor is not running.

    Returns Promise<void>

Generated using TypeDoc