private async Task<EventHubReceiver> CreateEventHubReceiverAsync()
        {
            mState = await mOptions.StateFactory.GetOrCreateAsync(mPartitionId);


            if (null == mState && string.IsNullOrEmpty(mState.PartitionId))
                throw new InvalidOperationException("State factory returned invalid state, expected state not null && matching partition id");



            if (string.IsNullOrEmpty(mState.Offset)) // no saved state
            {
                if (!mOptions.IsOffset && !mOptions.IsStartUTCDateTime) // no starting point provided
                {
                    if (mOptions.IsEpoch) 
                        return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Epoch);
                    else
                        return await mConsumerGroup.CreateReceiverAsync(mPartitionId);
                }
                else // starting point IS PROVIDED
                {
                    if (mOptions.IsOffset) // starting point is offset
                    {
                        if (mOptions.IsEpoch)
                            return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Offset, mOptions.IsOffsetInclusive, mOptions.Epoch);
                        else
                            return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Offset, mOptions.IsOffsetInclusive);
                    }
                    else // starting point is datetime (UTC)
                    {
                        if (mOptions.IsEpoch) 
                            return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.StartUTCDateTime, mOptions.Epoch);
                        else
                            return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.StartUTCDateTime);

                    }
                }
            }
            else // previously saved state.
            {
                if (mOptions.IsEpoch)
                    return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mState.Offset, false, mOptions.Epoch);
                else
                    return await mConsumerGroup.CreateReceiverAsync(mPartitionId, mState.Offset, false);
            }
           
        } 
コード例 #2
0
        public Task<bool> ProcessEventsAsync(IEnumerable<EventData> events, IEventHubPartitionState state)
        {
            foreach (var evt in events)
            {
                ServiceEventSource.Current.Message("Got Event:{0}", Encoding.UTF8.GetString(evt.GetBytes()));

                /*
                    optionally update the state on event by event bases.
                    state.Offset = evt.Offset;
                    await state.SaveAsync();
                */
            }

            // or tell the listener to update the state batch by batch
            return Task.FromResult(true);

            // if you return false here, you are responsible to save the state when you see fit
        }
コード例 #3
0
        public Task <bool> ProcessEventsAsync(IEnumerable <EventData> events, IEventHubPartitionState state)
        {
            foreach (var evt in events)
            {
                ServiceEventSource.Current.Message("Got Event:{0}", Encoding.UTF8.GetString(evt.GetBytes()));

                /*
                 *  optionally update the state on event by event bases.
                 *  state.Offset = evt.Offset;
                 *  await state.SaveAsync();
                 */
            }

            // or tell the listener to update the state batch by batch
            return(Task.FromResult(true));

            // if you return false here, you are responsible to save the state when you see fit
        }
コード例 #4
0
        private async Task <EventHubReceiver> CreateEventHubReceiverAsync()
        {
            mState = await mOptions.StateFactory.GetOrCreateAsync(mPartitionId);


            if (null == mState && string.IsNullOrEmpty(mState.PartitionId))
            {
                throw new InvalidOperationException("State factory returned invalid state, expected state not null && matching partition id");
            }



            if (string.IsNullOrEmpty(mState.Offset))                    // no saved state
            {
                if (!mOptions.IsOffset && !mOptions.IsStartUTCDateTime) // no starting point provided
                {
                    if (mOptions.IsEpoch)
                    {
                        return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Epoch));
                    }
                    else
                    {
                        return(await mConsumerGroup.CreateReceiverAsync(mPartitionId));
                    }
                }
                else // starting point IS PROVIDED
                {
                    if (mOptions.IsOffset) // starting point is offset
                    {
                        if (mOptions.IsEpoch)
                        {
                            return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Offset, mOptions.IsOffsetInclusive, mOptions.Epoch));
                        }
                        else
                        {
                            return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.Offset, mOptions.IsOffsetInclusive));
                        }
                    }
                    else // starting point is datetime (UTC)
                    {
                        if (mOptions.IsEpoch)
                        {
                            return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.StartUTCDateTime, mOptions.Epoch));
                        }
                        else
                        {
                            return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mOptions.StartUTCDateTime));
                        }
                    }
                }
            }
            else // previously saved state.
            {
                if (mOptions.IsEpoch)
                {
                    return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mState.Offset, false, mOptions.Epoch));
                }
                else
                {
                    return(await mConsumerGroup.CreateReceiverAsync(mPartitionId, mState.Offset, false));
                }
            }
        }