Exemplo n.º 1
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="PartitionPump"/> class.
 /// </summary>
 ///
 /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param>
 /// <param name="consumerGroup">The name of the consumer group this partition pump is associated with.  Events are read in the context of this group.</param>
 /// <param name="partitionContext">The context of the Event Hub partition this partition pump is associated with.  Events will be read only from this partition.</param>
 /// <param name="partitionProcessor">A partition processor used to process events and errors.  Its implementation must be provided by the caller.</param>
 /// <param name="options">The set of options to use for this partition pump.</param>
 ///
 internal PartitionPump(EventHubClient eventHubClient,
                        string consumerGroup,
                        PartitionContext partitionContext,
                        BasePartitionProcessor partitionProcessor,
                        EventProcessorOptions options)
 {
     InnerClient        = eventHubClient;
     ConsumerGroup      = consumerGroup;
     Context            = partitionContext;
     PartitionProcessor = partitionProcessor;
     Options            = options;
 }
Exemplo n.º 2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="PartitionPump"/> class.
 /// </summary>
 ///
 /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param>
 /// <param name="consumerGroup">The name of the consumer group this partition pump is associated with.  Events are read in the context of this group.</param>
 /// <param name="partitionId">The identifier of the Event Hub partition this partition pump is associated with.  Events will be read only from this partition.</param>
 /// <param name="partitionProcessor">A partition processor used to process events and errors.  Its implementation must be provided by the caller.</param>
 /// <param name="options">The set of options to use for this partition pump.</param>
 ///
 internal PartitionPump(EventHubClient eventHubClient,
                        string consumerGroup,
                        string partitionId,
                        IPartitionProcessor partitionProcessor,
                        EventProcessorOptions options)
 {
     InnerClient        = eventHubClient;
     ConsumerGroup      = consumerGroup;
     PartitionId        = partitionId;
     PartitionProcessor = partitionProcessor;
     Options            = options;
 }
Exemplo n.º 3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessor"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group this event processor is associated with.  Events are read in the context of this group.</param>
        /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param>
        /// <param name="partitionProcessorFactory">Creates an instance of a class implementing the <see cref="IPartitionProcessor" /> interface.</param>
        /// <param name="partitionManager">Interacts with the storage system, dealing with ownership and checkpoints.</param>
        /// <param name="options">The set of options to use for this event processor.</param>
        ///
        /// <remarks>
        ///   Ownership of the <paramref name="eventHubClient" /> is assumed to be responsibility of the caller; this
        ///   processor will delegate operations to it, but will not perform any clean-up tasks, such as closing or
        ///   disposing of the instance.
        /// </remarks>
        ///
        public EventProcessor(string consumerGroup,
                              EventHubClient eventHubClient,
                              Func <PartitionContext, CheckpointManager, IPartitionProcessor> partitionProcessorFactory,
                              PartitionManager partitionManager,
                              EventProcessorOptions options = default)
        {
            Guard.ArgumentNotNullOrEmpty(nameof(consumerGroup), consumerGroup);
            Guard.ArgumentNotNull(nameof(eventHubClient), eventHubClient);
            Guard.ArgumentNotNull(nameof(partitionProcessorFactory), partitionProcessorFactory);
            Guard.ArgumentNotNull(nameof(partitionManager), partitionManager);

            InnerClient               = eventHubClient;
            ConsumerGroup             = consumerGroup;
            PartitionProcessorFactory = partitionProcessorFactory;
            Manager = partitionManager;
            Options = options?.Clone() ?? new EventProcessorOptions();

            Identifier     = Guid.NewGuid().ToString();
            PartitionPumps = new ConcurrentDictionary <string, PartitionPump>();
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventProcessor{T}"/> class.
        /// </summary>
        ///
        /// <param name="consumerGroup">The name of the consumer group this event processor is associated with.  Events are read in the context of this group.</param>
        /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param>
        /// <param name="partitionProcessorFactory">Creates a partition processor instance for the associated <see cref="PartitionContext" />.</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 this event processor.</param>
        ///
        /// <remarks>
        ///   Ownership of the <paramref name="eventHubClient" /> is assumed to be responsibility of the caller; this
        ///   processor will delegate operations to it, but will not perform any clean-up tasks, such as closing or
        ///   disposing of the instance.
        /// </remarks>
        ///
        public EventProcessor(string consumerGroup,
                              EventHubClient eventHubClient,
                              Func <PartitionContext, BasePartitionProcessor> partitionProcessorFactory,
                              PartitionManager partitionManager,
                              EventProcessorOptions options = default)
        {
            Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup));
            Argument.AssertNotNull(eventHubClient, nameof(eventHubClient));
            Argument.AssertNotNull(partitionProcessorFactory, nameof(partitionProcessorFactory));
            Argument.AssertNotNull(partitionManager, nameof(partitionManager));

            InnerClient               = eventHubClient;
            ConsumerGroup             = consumerGroup;
            PartitionProcessorFactory = partitionProcessorFactory;
            Manager = partitionManager;
            Options = options?.Clone() ?? new EventProcessorOptions();

            Identifier     = Guid.NewGuid().ToString();
            PartitionPumps = new ConcurrentDictionary <string, PartitionPump>();
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Creates and starts a new partition pump associated with the specified partition.  Partition pumps that are overwritten by the creation
        ///   of a new one are properly stopped.
        /// </summary>
        ///
        /// <param name="partitionId">The identifier of the Event Hub partition the partition pump will be associated with.  Events will be read only from this partition.</param>
        /// <param name="initialSequenceNumber">The sequence number of the event within a partition where the partition pump should begin reading events.</param>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        ///
        private async Task AddOrOverwritePartitionPumpAsync(string partitionId,
                                                            long?initialSequenceNumber)
        {
            // Remove and stop the existing partition pump if it exists.  We are not specifying any close reason because partition
            // pumps only are overwritten in case of failure.  In these cases, the close reason is delegated to the pump as it may
            // have more information about what caused the failure.

            await RemovePartitionPumpIfItExistsAsync(partitionId).ConfigureAwait(false);

            // Create and start the new partition pump and add it to the dictionary.

            var partitionContext = new PartitionContext(InnerClient.FullyQualifiedNamespace, InnerClient.EventHubName, ConsumerGroup, partitionId, Identifier, Manager);

            try
            {
                BasePartitionProcessor partitionProcessor = PartitionProcessorFactory(partitionContext);
                EventProcessorOptions  options            = Options.Clone();

                // Ovewrite the initial event position in case a checkpoint exists.

                if (initialSequenceNumber.HasValue)
                {
                    options.InitialEventPosition = EventPosition.FromSequenceNumber(initialSequenceNumber.Value);
                }

                var partitionPump = new PartitionPump(InnerClient, ConsumerGroup, partitionContext, partitionProcessor, options);

                await partitionPump.StartAsync().ConfigureAwait(false);

                PartitionPumps[partitionId] = partitionPump;
            }
            catch (Exception)
            {
                // If partition pump creation fails, we'll try again on the next time this method is called.  This should happen
                // on the next load balancing loop as long as this instance still owns the partition.
                // TODO: delegate the exception handling to an Exception Callback.
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="EventProcessor{T}"/> class.
 /// </summary>
 ///
 /// <param name="consumerGroup">The name of the consumer group this event processor is associated with.  Events are read in the context of this group.</param>
 /// <param name="eventHubClient">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 this event processor.</param>
 ///
 /// <remarks>
 ///   Ownership of the <paramref name="eventHubClient" /> is assumed to be responsibility of the caller; this
 ///   processor will delegate operations to it, but will not perform any clean-up tasks, such as closing or
 ///   disposing of the instance.
 /// </remarks>
 ///
 public EventProcessor(string consumerGroup,
                       EventHubClient eventHubClient,
                       PartitionManager partitionManager,
                       EventProcessorOptions options = default) : this(consumerGroup, eventHubClient, partitionContext => new T(), partitionManager, options)
 {
 }