Question

nielsb on Thu, 13 Nov 2014 18:32:31


Hi!

So, I've been playing around with EventHub's, and they seem very cool! A question I have is; when I use to create event consumers by using the EventHubProcessor, how do I define a start-up offset. I.e. where to start to read from in the hub? When I create a single EventHubReceiver I can define the offset in the CreateReceiverAsync method from the EventHubConsumerGroup, but when I use an EventHubProcessor and RegisterEventProcessorAsync I can't seem to find how to do that.

Niels


http://www.nielsberglund.com | @nielsberglund


Sponsored



Replies

Serkant Karaca on Thu, 13 Nov 2014 19:13:31


Look at the Lease class definition: http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.lease.aspx

You can set the offset in the lease.

nielsb on Thu, 13 Nov 2014 19:41:54


Look at the Lease class definition: http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.lease.aspx.

Hi Serkant,

OK, so I am probably stupid - but I still don't see where to do this. The only place I could potentially think of is in the OpenAsync method of IEventProcessor, i.e. in my event processor class I would set the offset in that particular method? I guess I would get the offset from the storage, yes???

Niels

Serkant Karaca on Thu, 13 Nov 2014 19:49:35


Here's a simple code snipped showing how you can define offset in the lease. Let me know if this doesn't work.

Lease lease = new Lease()
{
    PartitionId = "1",
    Offset = "1234567890"
};

myConsumerGroup.RegisterProcessorFactoryAsync(lease, new MyCheckpointManager(), processorFactory).Wait();


nielsb on Sat, 15 Nov 2014 07:58:53


Here's a simple code snipped showing how you can define offset in the lease. Let me know if this doesn't work.

Hi Serkant!

Thanks for the code. Now I believe I (kind of) know how it works! BTW, how expensive is the CheckPoint call, i.e. how bad would it be to do a CheckPoint after each processed message? Reasoning behind it is that I do not want to do a restart after a catastrophic failure and receive already processed events, which I most likely would get with a time-based check point.

Niels