コード例 #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessorManager"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group the event processors are associated with.  Events are read in the context of this group.</param>
        /// <param name="client">The client used to interact with the Azure Event Hubs service.</param>
        /// <param name="partitionManager">Interacts with the storage system with responsibility for creation of checkpoints and for ownership claim.</param>
        /// <param name="options">The set of options to use for the event processors.</param>
        /// <param name="onInitialize">A callback action to be called on <see cref="PartitionProcessor.InitializeAsync" />.</param>
        /// <param name="onClose">A callback action to be called on <see cref="PartitionProcessor.CloseAsync" />.</param>
        /// <param name="onProcessEvents">A callback action to be called on <see cref="PartitionProcessor.ProcessEventsAsync" />.</param>
        /// <param name="onProcessError">A callback action to be called on <see cref="PartitionProcessor.ProcessErrorAsync" />.</param>
        ///
        public EventProcessorManager(string consumerGroup,
                                     EventHubClient client,
                                     PartitionManager partitionManager      = null,
                                     EventProcessorOptions options          = null,
                                     Action <PartitionContext> onInitialize = null,
                                     Action <PartitionContext, PartitionProcessorCloseReason> onClose = null,
                                     Action <PartitionContext, IEnumerable <EventData>, CancellationToken> onProcessEvents = null,
                                     Action <PartitionContext, Exception, CancellationToken> onProcessError = null)
        {
            ConsumerGroup = consumerGroup;
            InnerClient   = client;

            PartitionProcessorFactory = partitionContext =>
                                        new PartitionProcessor
                                        (
                onInitialize,
                onClose,
                onProcessEvents,
                onProcessError
                                        );

            InnerPartitionManager = partitionManager ?? new InMemoryPartitionManager();

            // In case it has not been specified, set the maximum receive wait time to 2 seconds because the default
            // value (1 minute) would take too much time.

            Options = options?.Clone() ?? new EventProcessorOptions();

            if (Options.MaximumReceiveWaitTime == null)
            {
                Options.MaximumReceiveWaitTime = TimeSpan.FromSeconds(2);
            }

            EventProcessors = new List <EventProcessor <PartitionProcessor> >();
        }
コード例 #2
0
        public void CloneProducesACopy()
        {
            var options = new EventProcessorOptions
            {
                InitialEventPosition   = EventPosition.FromOffset(55),
                MaximumMessageCount    = 43,
                MaximumReceiveWaitTime = TimeSpan.FromMinutes(65)
            };

            var clone = options.Clone();

            Assert.That(clone, Is.Not.Null, "The clone should not be null.");
            Assert.That(clone, Is.Not.SameAs(options), "The clone should be a different instance.");

            Assert.That(clone.InitialEventPosition, Is.EqualTo(options.InitialEventPosition), "The initial event position of the clone should match.");
            Assert.That(clone.MaximumMessageCount, Is.EqualTo(options.MaximumMessageCount), "The maximum message count of the clone should match.");
            Assert.That(clone.MaximumReceiveWaitTime, Is.EqualTo(options.MaximumReceiveWaitTime), "The maximum receive wait time of the clone should match.");
        }
コード例 #3
0
        public void CloneProducesACopy()
        {
            var options = new EventProcessorOptions
            {
                RetryOptions = new EventHubsRetryOptions {
                    Mode = EventHubsRetryMode.Fixed
                },
                ConnectionOptions = new EventHubConnectionOptions {
                    TransportType = EventHubsTransportType.AmqpWebSockets
                },
                MaximumWaitTime                      = TimeSpan.FromMilliseconds(9994),
                PrefetchCount                        = 65,
                LoadBalancingUpdateInterval          = TimeSpan.FromDays(3),
                PartitionOwnershipExpirationInterval = TimeSpan.FromHours(16),
                Identifier = "Rick Springfield is a bad friend",
                TrackLastEnqueuedEventProperties = false,
                DefaultStartingPosition          = EventPosition.FromOffset(555)
            };

            EventProcessorOptions clone = options.Clone();

            Assert.That(clone, Is.Not.Null, "The clone should not be null.");
            Assert.That(clone, Is.Not.SameAs(options), "The options should be a copy, not the same instance.");

            Assert.That(clone.ConnectionOptions.TransportType, Is.EqualTo(options.ConnectionOptions.TransportType), "The connection options of the clone should copy properties.");
            Assert.That(clone.ConnectionOptions, Is.Not.SameAs(options.ConnectionOptions), "The connection options of the clone should be a copy, not the same instance.");
            Assert.That(clone.RetryOptions.IsEquivalentTo(options.RetryOptions), Is.True, "The retry options of the clone should be considered equal.");
            Assert.That(clone.RetryOptions, Is.Not.SameAs(options.RetryOptions), "The retry options of the clone should be a copy, not the same instance.");
            Assert.That(clone.MaximumWaitTime, Is.EqualTo(options.MaximumWaitTime), "The maximum wait time should match.");
            Assert.That(clone.PrefetchCount, Is.EqualTo(options.PrefetchCount), "The prefetch count should match.");
            Assert.That(clone.PrefetchSizeInBytes, Is.EqualTo(options.PrefetchSizeInBytes), "The prefetch size should match.");
            Assert.That(clone.LoadBalancingUpdateInterval, Is.EqualTo(options.LoadBalancingUpdateInterval), "The load balancing update interval should match.");
            Assert.That(clone.PartitionOwnershipExpirationInterval, Is.EqualTo(options.PartitionOwnershipExpirationInterval), "The partition ownership interval should match.");
            Assert.That(clone.Identifier, Is.EqualTo(options.Identifier), "The identifier should match.");
            Assert.That(clone.TrackLastEnqueuedEventProperties, Is.EqualTo(options.TrackLastEnqueuedEventProperties), "Tracking of last enqueued events should match.");
            Assert.That(clone.DefaultStartingPosition, Is.EqualTo(options.DefaultStartingPosition), "The default starting position should match.");
            Assert.That(clone.LoadBalancingStrategy, Is.EqualTo(options.LoadBalancingStrategy), "The load balancing strategy should match.");
        }