Пример #1
0
        /// <summary>
        ///   Adds new uninitialized event processors instances to this hub.
        /// </summary>
        ///
        /// <param name="amount">The amount of event processors to add.</param>
        ///
        public void AddEventProcessors(int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                var eventProcessor = new ShortWaitTimeMock
                                     (
                    InnerPartitionManager,
                    ConsumerGroup,
                    FullyQualifiedNamespace,
                    EventHubName,
                    ConnectionFactory,
                    ClientOptions
                                     );

                if (OnInitialize != null)
                {
                    eventProcessor.PartitionInitializingAsync += eventArgs =>
                    {
                        OnInitialize(eventArgs);
                        return(Task.CompletedTask);
                    };
                }

                if (OnStop != null)
                {
                    eventProcessor.PartitionClosingAsync += eventArgs =>
                    {
                        OnStop(eventArgs);
                        return(Task.CompletedTask);
                    };
                }

                eventProcessor.ProcessEventAsync += eventArgs =>
                {
                    OnProcessEvent?.Invoke(eventArgs);
                    return(Task.CompletedTask);
                };

                eventProcessor.ProcessErrorAsync += eventArgs =>
                {
                    OnProcessError?.Invoke(eventArgs);
                    return(Task.CompletedTask);
                };

                EventProcessors.Add(eventProcessor);
            }
        }
        /// <summary>
        ///   Adds new uninitialized event processors instances to this hub.
        /// </summary>
        ///
        /// <param name="amount">The amount of event processors to add.</param>
        ///
        public void AddEventProcessors(int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                var eventProcessor = new ShortWaitTimeMock
                                     (
                    ConsumerGroup,
                    InnerPartitionManager,
                    Connection,
                    Options
                                     );

                if (OnInitialize != null)
                {
                    eventProcessor.InitializeProcessingForPartitionAsyncHandler = initializationContext =>
                    {
                        OnInitialize(initializationContext);
                        return(new ValueTask());
                    };
                }

                if (OnStop != null)
                {
                    eventProcessor.ProcessingForPartitionStoppedAsyncHandler = stopContext =>
                    {
                        OnStop(stopContext);
                        return(new ValueTask());
                    };
                }

                eventProcessor.ProcessEventAsyncHandler = processorEvent =>
                {
                    OnProcessEvent?.Invoke(processorEvent);
                    return(new ValueTask());
                };

                eventProcessor.ProcessErrorAsyncHandler = errorContext =>
                {
                    OnProcessException?.Invoke(errorContext);
                    return(new ValueTask());
                };

                EventProcessors.Add(eventProcessor);
            }
        }
Пример #3
0
        /// <summary>
        ///   Adds new uninitialized event processors instances to this hub.
        /// </summary>
        ///
        /// <param name="amount">The amount of event processors to add.</param>
        ///
        public void AddEventProcessors(int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                var eventProcessor = new ShortWaitTimeMock
                                     (
                    ConsumerGroup,
                    InnerPartitionManager,
                    Connection,
                    Options
                                     );

                if (OnInitialize != null)
                {
                    eventProcessor.InitializeProcessingForPartitionAsync = (partitionContext) =>
                    {
                        OnInitialize(partitionContext);
                        return(Task.CompletedTask);
                    };
                }

                if (OnClose != null)
                {
                    eventProcessor.ProcessingForPartitionStoppedAsync = (partitionContext, reason) =>
                    {
                        OnClose(partitionContext, reason);
                        return(Task.CompletedTask);
                    };
                }

                eventProcessor.ProcessEventsAsync = (partitionContext, events) =>
                {
                    OnProcessEvents?.Invoke(partitionContext, events);
                    return(Task.CompletedTask);
                };

                eventProcessor.ProcessExceptionAsync = (partitionContext, exception) =>
                {
                    OnProcessException?.Invoke(partitionContext, exception);
                    return(Task.CompletedTask);
                };

                EventProcessors.Add(eventProcessor);
            }
        }