title: understanding check pointing in eventhub
body: <p>I want to ensure that, if my eventhub client crashes (currently a console application), it only picks up events it has not yet taken from the eventhub. One way to achieve this, is to exploit offsets. However, this (to my understanding) requires the client to store the latest offset (besides events do not necessarily seem to hit the foreach loop of the ProcessEventsAsync method ordered by SequenceNumber). </p>
  
  <p>An alternative, is to use checkpoints. I think they are persisted via the server (eventhub) using the provided storage account credentials. Is this correct?</p>
  
  <p>This is some preliminary code I am currently using:</p>
  
  <pre><code>public class SimpleEventProcessor : IEventProcessor
  {
      private Stopwatch _checkpointStopWatch;
  
      async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
      {
          Console.WriteLine("Processor Shutting Down. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason);
          if (reason == CloseReason.Shutdown)
          {
              await context.CheckpointAsync();
          }
      }
  
      Task IEventProcessor.OpenAsync(PartitionContext context)
      {
          Console.WriteLine("SimpleEventProcessor initialized.  Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset);
          _checkpointStopWatch = new Stopwatch();
          _checkpointStopWatch.Start();
          return Task.FromResult&lt;object&gt;(null);
      }
  
      async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable&lt;EventData&gt; messages)
      {
          foreach (var eventData in messages)
          {
              // do something                    
          }
  
          //Call checkpoint every 5 minutes, so that worker can resume processing from 5 minutes back if it restarts.
          if (_checkpointStopWatch.Elapsed &gt; TimeSpan.FromMinutes(5))
          {
              await context.CheckpointAsync();
              _checkpointStopWatch.Restart();
          }
      }
  }
  </code></pre>
  
  <p>I believe it sends creates a checkpoint to the server every 5 minutes. How does the server know, which client has submitted the checkpoint (via the context)? Also, how can I prevent events from processed again if the client restarts? Furthermore, there could still be an up to 5 minutes window in which events are processed again. Perhaps I should rather use a queue/topic given my requirement?</p>
  
  <p>PS:</p>
  
  <p>This seems to be sufficient:</p>
  
  <pre><code>async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable&lt;EventData&gt; messages)
  {
      foreach (var eventData in messages)
      {
          // do something
      }
      await context.CheckpointAsync();
  }
  </code></pre>