Interface IEventProcessor


  • public interface IEventProcessor
    Interface that must be implemented by event processor classes.

    Any given instance of an event processor class will only process events from one partition of one Event Hub. A PartitionContext is provided with each call to the event processor because some parameters could change, but it will always be the same partition.

    Although EventProcessorHost is multithreaded, calls to a given instance of an event processor class are serialized, except for onError(). onOpen() is called first, then onEvents() will be called zero or more times. When the event processor needs to be shut down, whether because there was a failure somewhere, or the lease for the partition has been lost, or because the entire processor host is being shut down, onClose() is called after the last onEvents() call returns.

    onError() could be called while onEvents() or onClose() is executing. No synchronization is attempted in order to avoid possibly deadlocking.

    • Method Detail

      • onOpen

        void onOpen​(PartitionContext context)
             throws Exception
        Called by processor host to initialize the event processor.

        If onOpen fails, this event processor host instance will give up ownership of the partition.

        Parameters:
        context - Information about the partition that this event processor will process events from.
        Throws:
        Exception - to indicate failure.
      • onClose

        void onClose​(PartitionContext context,
                     CloseReason reason)
              throws Exception
        Called by processor host to indicate that the event processor is being stopped.

        If onClose fails, the exception is reported to the general exception notification handler set via EventProcessorOptions, if any, but is otherwise ignored.

        Parameters:
        context - Information about the partition.
        reason - Reason why the event processor is being stopped.
        Throws:
        Exception - to indicate failure.
      • onEvents

        void onEvents​(PartitionContext context,
                      Iterable<EventData> events)
               throws Exception
        Called by the processor host when a batch of events has arrived.

        This is where the real work of the event processor is done. It is normally called when one or more events have arrived. If the EventProcessorHost instance was set up with an EventProcessorOptions on which setInvokeProcessorAfterReceiveTimeout(true) has been called, then when a receive times out, onEvents will be called with an empty iterable. By default this option is false and receive timeouts do not cause a call to this method.

        Parameters:
        context - Information about the partition.
        events - The events to be processed. May be empty.
        Throws:
        Exception - to indicate failure.
      • onError

        void onError​(PartitionContext context,
                     Throwable error)
        Called when the underlying client experiences an error while receiving. EventProcessorHost will take care of recovering from the error and continuing to pump events, so no action is required from your code. This method is provided for informational purposes.
        Parameters:
        context - Information about the partition.
        error - The error that occured.