Skip to content

Instantly share code, notes, and snippets.

@ceilingfish
Created December 4, 2019 08:28
Show Gist options
  • Select an option

  • Save ceilingfish/7fd6e07bf1bb0acec184c191f2f1ddb7 to your computer and use it in GitHub Desktop.

Select an option

Save ceilingfish/7fd6e07bf1bb0acec184c191f2f1ddb7 to your computer and use it in GitHub Desktop.
Rewinding azure event hub offsets
async Task Main()
{
var connectionString = "Endpoint=sb://my-namespace.servicebus.windows.net/;SharedAccessKeyName=ReadEvents;SharedAccessKey=MySecretKey;EntityPath=hub";
Console.WriteLine("Rewinding event hub...");
var eventProcessorHost = new EventProcessorHost(
"reporting",
PartitionReceiver.DefaultConsumerGroupName,
connectionString,
"UseDevelopmentStorage=true",
"azure-webjobs-eventhub");
EventProcessorOptions options = new EventProcessorOptions()
{
InitialOffsetProvider = (partitionId) => EventPosition.FromEnqueuedTime(new DateTime(2019,12, 3,0,0,0))
};
await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options);
await eventProcessorHost.UnregisterEventProcessorAsync();
}
public class SimpleEventProcessor : IEventProcessor
{
public Task CloseAsync(PartitionContext context, CloseReason reason) => Task.CompletedTask;
public Task OpenAsync(PartitionContext context) => Task.CompletedTask;
public Task ProcessErrorAsync(PartitionContext context, Exception error) => Task.CompletedTask;
public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages) => Task.CompletedTask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment