private Task PartitionInitializingHandler(PartitionInitializingEventArgs args)
 {
     args.DefaultStartingPosition = EventPosition.Latest;
     Console.WriteLine("_partitionsInitialized.Release();");
     _partitionsInitialized.Release();
     return(Task.CompletedTask);
 }
Esempio n. 2
0
        protected virtual async Task ProcessInitializingHandler(PartitionInitializingEventArgs initArgs)
        {
            var partitionId = initArgs.PartitionId;

            Logger.LogTrace($"Initializing partition {partitionId}");

            if (initArgs.CancellationToken.IsCancellationRequested)
            {
                // Log the condition where the initialization handler is called, an the PartitionInitializingEventArgs contains a cancellation request.
                Logger.LogTrace($"PartitionInitializingEventArgs contain a cancellation request {partitionId}");
            }

            try
            {
                var checkpoint = await CheckpointClient.GetCheckpointForPartitionAsync(partitionId, initArgs.CancellationToken);

                initArgs.DefaultStartingPosition = EventPosition.FromEnqueuedTime(checkpoint.LastProcessed);
                Logger.LogTrace($"Starting to read partition {partitionId} from checkpoint {checkpoint.LastProcessed}");
                Logger.LogMetric(EventMetrics.EventHubPartitionInitialized(partitionId), 1);
            }
#pragma warning disable CA1031
            catch (Exception ex)
#pragma warning restore CA1031
            {
                Logger.LogTrace($"Failed to initialize partition {partitionId} from checkpoint");

                EventHubExceptionProcessor.ProcessException(ex, Logger, errorMetricName: EventHubErrorCode.EventHubPartitionInitFailed.ToString());
            }
        }
        public async Task OnPartitionInitializing(PartitionInitializingEventArgs eventArgs)
        {
            LogContext.SetCurrentIfNull(_hostConfiguration.ReceiveLogContext);

            _data.TryAdd(eventArgs.PartitionId, _ => new PartitionCheckpointData(_receiveSettings));
            LogContext.Info?.Log("Partition: {PartitionId} was initialized", eventArgs.PartitionId);
        }
Esempio n. 4
0
 /// <summary>
 /// Event handler that ensures only newest events are processed
 /// </summary>
 /// <param name="arg">Init event args</param>
 /// <returns>Completed Task, no async work needed</returns>
 private Task Client_PartitionInitializingAsync(PartitionInitializingEventArgs arg)
 {
     _logger.LogInformation("EventProcessorClient initializing, start with latest position for " +
                            "partition {PartitionId}", arg.PartitionId);
     arg.DefaultStartingPosition = EventPosition.Latest;
     return(Task.CompletedTask);
 }
        Task OnPartitionInitializing(PartitionInitializingEventArgs eventArgs)
        {
            LogContext.SetCurrentIfNull(_logContext);

            _data.TryAdd(eventArgs.PartitionId, _ => new PartitionCheckpointData(_timeout, _maxCount));
            LogContext.Info?.Log("Partition: {PartitionId} was initialized", eventArgs.PartitionId);
            return(TaskUtil.Completed);
        }
Esempio n. 6
0
        /// <summary>
        /// Event handler for monitoring partition initializing events.
        /// </summary>
        private async Task Client_PartitionInitializingAsync(PartitionInitializingEventArgs arg)
        {
            _logger.LogInformation("EventProcessorClient partition initializing, start with latest position for " +
                                   "partition {PartitionId}", arg.PartitionId);

            arg.DefaultStartingPosition = EventPosition.Latest;

            await _lockInitializedPartitions.WaitAsync().ConfigureAwait(false);

            try {
                _initializedPartitions[arg.PartitionId] = true;
            }
            finally {
                _lockInitializedPartitions.Release();
            }
        }
Esempio n. 7
0
        private Task InitializeEventHandler(PartitionInitializingEventArgs args)
        {
            try
            {
                if (args.CancellationToken.IsCancellationRequested)
                {
                    return(Task.CompletedTask);
                }

                log.LogDebug($"Initialize EventHub partition: { args.PartitionId } from EnqueueTime {utcMonitorStart}");

                // If no checkpoint was found, start processing events enqueued now -5 minutes or in the future.
                // This should be the case -- rely on timestamp, not a checkpoint to ensure nothing is missed across multiple instances
                EventPosition startPositionWhenNoCheckpoint = EventPosition.FromEnqueuedTime(utcMonitorStart);
                args.DefaultStartingPosition = startPositionWhenNoCheckpoint;
            }
            catch
            {
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 ///   A simulated method for handling an exception that occurs during
 ///   partition initialization.
 /// </summary>
 ///
 /// <param name="eventArgs">The arguments associated with the failed initialization handling.</param>
 /// <param name="exception">The exception to handle.</param>
 ///
 public static void HandleInitializeException(PartitionInitializingEventArgs eventArgs,
                                              Exception exception)
 {
 }
 private Task PartitionInitializingAsync(PartitionInitializingEventArgs arg)
 {
     arg.DefaultStartingPosition = EventPosition.Latest;
     return(Task.CompletedTask);
 }
        private Task ProcessorOnPartitionInitializingAsync(PartitionInitializingEventArgs arg)
        {
            Console.WriteLine($"Initializing partition {arg.PartitionId}");

            return(Task.CompletedTask);
        }
Esempio n. 11
0
 private Task ProcessorInitHandler(PartitionInitializingEventArgs eventArgs)
 {
     _logger.LogInformation($"SimpleEventProcessor initialized. Partition: '{eventArgs.PartitionId}'");
     return(Task.CompletedTask);
 }