Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The factory to create metric recorders from</param>
        /// <param name="consumerGroupName">The name of the consumer group that the processor is associated with</param>
        /// <param name="storageAccount">The storage account used to access the Azure BLOB store</param>
        /// <param name="containerName">The name of the container that the BLOBs are contained in</param>
        /// <param name="subContainerPrefix">The prefix for the BLOB container</param>
        public AzureStorageEpochRecorder(ILogger logger, IMetricFactory metricFactory, string consumerGroupName, CloudStorageAccount storageAccount, string containerName, string subContainerPrefix)
        {
            Guard.NotNullOrWhitespace(nameof(consumerGroupName), consumerGroupName);
            Guard.NotNull(nameof(storageAccount), storageAccount);
            Guard.NotNull(nameof(logger), logger);
            AzureBlobCommon.ValidContainerName(nameof(containerName), containerName);

            _logger = logger;

            using (_logger.BeginScope("Azure Storage Lease Manager::ctor"))
            {
                _logger.LogInformation("Creating Azure lease manager for consumer group {consumerGroupName}, container {containerName}", containerName, consumerGroupName);

                subContainerPrefix = (subContainerPrefix != null) ? subContainerPrefix.Trim() : "";

                var storageClient = storageAccount.CreateCloudBlobClient();

                storageClient.DefaultRequestOptions = new BlobRequestOptions {
                    MaximumExecutionTime = TimeSpan.FromSeconds(60)
                };
                _epochStoreContainer    = storageClient.GetContainerReference(containerName);
                _consumerGroupDirectory = _epochStoreContainer.GetDirectoryReference($"{subContainerPrefix}{consumerGroupName}");

                _epochReadCounter          = metricFactory.CreateCounter("aer-checkpoint-read", "The number of times that the Azure Storage epoch recorder has read the epoch", false, new string[0]);
                _epochUpdateCounter        = metricFactory.CreateCounter("aer-checkpoint-update", "The number of times that the Azure Storage epoch recorder has updated the epoch", false, new string[0]);
                _epochErrorCounter         = metricFactory.CreateCounter("aer-checkpoint-error", "The number of times that the Azure Storage epoch recorder has errors raised", false, new string[0]);
                _storagePerformanceSummary = metricFactory.CreateSummary("aer-storage-timing", "The duration taken to access Azure Storage to perform checkpoint recorder operations", 10, false, new string[0]);
            }
        }
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="logger">The logger to write debugging and diagnostics information to</param>
        /// <param name="metricFactory">The factory to create metric recorders from</param>
        /// <param name="storageAccount">The storage account used to access the Azure BLOB store</param>
        /// <param name="containerName">The name of the container that the BLOBs are contained in</param>
        /// <param name="subContainerPrefix">The prefix for the BLOB container</param>
        public AzureStorageCheckpointManager(ILogger logger, IMetricFactory metricFactory, CloudStorageAccount storageAccount, string containerName, string subContainerPrefix)
        {
            Guard.NotNull(nameof(storageAccount), storageAccount);
            Guard.NotNull(nameof(logger), logger);
            AzureBlobCommon.ValidContainerName(nameof(containerName), containerName);

            _logger = logger;

            using (_logger.BeginScope("Azure Storage Checkpoint Manager::ctor"))
            {
                _logger.LogInformation("Creating Azure storage checkpoint manager for container {containerName}", containerName);
                _containerName      = containerName;
                _subContainerPrefix = (subContainerPrefix != null) ? subContainerPrefix.Trim() : "";

                _client = storageAccount.CreateCloudBlobClient();

                _checkpointReadCounter     = metricFactory.CreateCounter("acm-checkpoint-read", "The number of times that the Azure Storage checkpoint manager has read the checkpoint", false, new string[0]);
                _checkpointUpdateCounter   = metricFactory.CreateCounter("acm-checkpoint-update", "The number of times that the Azure Storage checkpoint manager has updated the checkpoint", false, new string[0]);
                _checkpointErrorCounter    = metricFactory.CreateCounter("acm-checkpoint-error", "The number of times that the Azure Storage checkpoint manager has errors raised", false, new string[0]);
                _storagePerformanceSummary = metricFactory.CreateSummary("acm-storage-timing", "The duration taken to access Azure Storage to perform checkpoint manager operations", 10, false, new string[0]);
            }
        }