Beispiel #1
0
        /// <inheritdoc />
        public EventHubContentLocationEventStore(
            ContentLocationEventStoreConfiguration configuration,
            IContentLocationEventHandler eventHandler,
            string localMachineName,
            CentralStorage centralStorage,
            Interfaces.FileSystem.AbsolutePath workingDirectory)
            : base(configuration, nameof(EventHubContentLocationEventStore), eventHandler, centralStorage, workingDirectory)
        {
            Contract.Requires(configuration.MaxEventProcessingConcurrency >= 1);
            _configuration    = configuration;
            _localMachineName = localMachineName;
            _eventHubClient   = CreateEventHubClient(configuration);
            _extraEventHubClientRetryPolicy = CreateEventHubClientRetryPolicy();

            if (configuration.MaxEventProcessingConcurrency > 1)
            {
                _eventProcessingBlocks =
                    Enumerable.Range(1, configuration.MaxEventProcessingConcurrency)
                    .Select(
                        (_, index) =>
                {
                    var serializer = new ContentLocationEventDataSerializer(configuration.SelfCheckSerialization ? ValidationMode.Trace : ValidationMode.Off);
                    return(new ActionBlock <ProcessEventsInput>(
                               t => ProcessEventsCoreAsync(t, serializer, index: index),
                               new ExecutionDataflowBlockOptions()
                    {
                        MaxDegreeOfParallelism = 1,
                        BoundedCapacity = configuration.EventProcessingMaxQueueSize,
                    }));
                })
                    .ToArray();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Factory method for creating an instance of <see cref="ContentLocationEventStore"/> based on <paramref name="configuration"/>.
        /// </summary>
        public static IEventHubClient CreateEventHubClient(ContentLocationEventStoreConfiguration configuration)
        {
            Contract.Requires(configuration != null);

            switch (configuration)
            {
            case EventHubContentLocationEventStoreConfiguration azureConfig:
                return(new AzureEventHubClient(azureConfig));

            case MemoryContentLocationEventStoreConfiguration memoryConfig:
                return(new MemoryEventHubClient(memoryConfig));

            default:
                throw new InvalidOperationException($"Unknown EventStore type '{configuration.GetType()}'.");
            }
        }