Exemplo n.º 1
0
        public async Task SendAndReceiveFromAzureQueue()
        {
            var options = new AzureQueueOptions
            {
                ConnectionString         = TestDefaultConfiguration.DataConnectionString,
                MessageVisibilityTimeout = TimeSpan.FromSeconds(30),
                QueueNames = azureQueueNames
            };
            var serializationManager = this.fixture.Services.GetService <SerializationManager>();
            var clusterOptions       = this.fixture.Services.GetRequiredService <IOptions <ClusterOptions> >();
            var queueCacheOptions    = new SimpleQueueCacheOptions();
            var queueDataAdapter     = new AzureQueueDataAdapterV2(serializationManager);
            var adapterFactory       = new AzureQueueAdapterFactory(
                AZURE_QUEUE_STREAM_PROVIDER_NAME,
                options,
                queueCacheOptions,
                queueDataAdapter,
                this.fixture.Services,
                clusterOptions,
                serializationManager,
                loggerFactory);

            adapterFactory.Init();
            await SendAndReceiveFromQueueAdapter(adapterFactory);
        }
Exemplo n.º 2
0
        private QueueClient GetCloudQueueClient(AzureQueueOptions options, ILogger logger)
        {
            try
            {
                var clientOptions = new QueueClientOptions
                {
                    Retry =
                    {
                        Mode           = RetryMode.Fixed,
                        Delay          = AzureQueueDefaultPolicies.PauseBetweenQueueOperationRetries,
                        MaxRetries     = AzureQueueDefaultPolicies.MaxQueueOperationRetries,
                        NetworkTimeout = AzureQueueDefaultPolicies.QueueOperationTimeout,
                    }
                };

                var client = options.ServiceUri != null
                    ? new QueueClient(new Uri(options.ServiceUri, QueueName), options.TokenCredential, clientOptions)
                    : new QueueClient(options.ConnectionString, QueueName, clientOptions);
                return(client);
            }
            catch (Exception exc)
            {
                logger.Error((int)AzureQueueErrorCode.AzureQueue_14, String.Format("Error creating GetCloudQueueOperationsClient."), exc);
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Helper method for testing. Clears all messages in all the queues used by the specified stream provider.
        /// </summary>
        /// <param name="loggerFactory">logger factory to use</param>
        /// <param name="azureQueueNames">The deployment ID hosting the stream provider.</param>
        /// <param name="storageConnectionString">The azure storage connection string.</param>
        public static async Task ClearAllUsedAzureQueues(ILoggerFactory loggerFactory, List <string> azureQueueNames, string storageConnectionString)
        {
            var options = new AzureQueueOptions();

            options.ConfigureQueueServiceClient(storageConnectionString);
            await ClearAllUsedAzureQueues(loggerFactory, azureQueueNames, options);
        }
Exemplo n.º 4
0
        private static AzureQueueOptions ConfigureOptions(string storageConnectionString, TimeSpan?visibilityTimeout)
        {
            var options = new AzureQueueOptions
            {
                MessageVisibilityTimeout = visibilityTimeout
            };

            options.ConfigureQueueServiceClient(storageConnectionString);
            return(options);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="loggerFactory">logger factory to use</param>
        /// <param name="queueName">Name of the queue to be connected to.</param>
        /// <param name="options">Queue connection options.</param>
        public AzureQueueDataManager(ILoggerFactory loggerFactory, string queueName, AzureQueueOptions options)
        {
            queueName = SanitizeQueueName(queueName);
            ValidateQueueName(queueName);

            logger    = loggerFactory.CreateLogger <AzureQueueDataManager>();
            QueueName = queueName;
            messageVisibilityTimeout = options.MessageVisibilityTimeout;
            this.options             = options;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="loggerFactory">logger factory to use</param>
        /// <param name="queueName">Name of the queue to be connected to.</param>
        /// <param name="options">Queue connection options.</param>
        public AzureQueueDataManager(ILoggerFactory loggerFactory, string queueName, AzureQueueOptions options)
        {
            queueName = SanitizeQueueName(queueName);
            ValidateQueueName(queueName);

            logger    = loggerFactory.CreateLogger <AzureQueueDataManager>();
            QueueName = queueName;
            messageVisibilityTimeout = options.MessageVisibilityTimeout;

            queueClient = GetCloudQueueClient(options, logger);
        }
Exemplo n.º 7
0
        private async Task <QueueClient> GetCloudQueueClient(AzureQueueOptions options, ILogger logger)
        {
            try
            {
                var client = await options.CreateClient();

                return(client.GetQueueClient(QueueName));
            }
            catch (Exception exc)
            {
                logger.LogError((int)AzureQueueErrorCode.AzureQueue_14, exc, "Error creating Azure Storage Queues client");
                throw;
            }
        }
Exemplo n.º 8
0
 public AzureQueueAdapter(
     IQueueDataAdapter <string, IBatchContainer> dataAdapter,
     IAzureStreamQueueMapper streamQueueMapper,
     ILoggerFactory loggerFactory,
     AzureQueueOptions queueOptions,
     string serviceId,
     string providerName)
 {
     this.queueOptions = queueOptions;
     ServiceId         = serviceId;
     Name = providerName;
     this.streamQueueMapper = streamQueueMapper;
     this.dataAdapter       = dataAdapter;
     this.loggerFactory     = loggerFactory;
 }
Exemplo n.º 9
0
        public async Task SendAndReceiveFromAzureQueue()
        {
            var options = new AzureQueueOptions
            {
                ConnectionString         = TestDefaultConfiguration.DataConnectionString,
                ClusterId                = this.clusterId,
                MessageVisibilityTimeout = TimeSpan.FromSeconds(30)
            };
            var adapterFactory = new AzureQueueAdapterFactory <AzureQueueDataAdapterV2>(AZURE_QUEUE_STREAM_PROVIDER_NAME, options,
                                                                                        new HashRingStreamQueueMapperOptions(), new SimpleQueueCacheOptions(), this.fixture.Services, this.fixture.Services.GetService <IOptions <ClusterOptions> >(),
                                                                                        this.fixture.Services.GetRequiredService <SerializationManager>(), loggerFactory);

            adapterFactory.Init();
            await SendAndReceiveFromQueueAdapter(adapterFactory);
        }
Exemplo n.º 10
0
 public AzureQueueAdapterFactory(
     string name,
     AzureQueueOptions options,
     SimpleQueueCacheOptions cacheOptions,
     IQueueDataAdapter <string, IBatchContainer> dataAdapter,
     IOptions <ClusterOptions> clusterOptions,
     ILoggerFactory loggerFactory)
 {
     this.providerName      = name;
     this.options           = options ?? throw new ArgumentNullException(nameof(options));
     this.dataAdapter       = dataAdapter ?? throw new ArgumentNullException(nameof(dataAdapter));;
     this.clusterOptions    = clusterOptions.Value;
     this.loggerFactory     = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.streamQueueMapper = new AzureStreamQueueMapper(options.QueueNames, providerName);
     this.adapterCache      = new SimpleQueueAdapterCache(cacheOptions, this.providerName, this.loggerFactory);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new instance of the <see cref="AzureQueueMessagePublisher"/>.
 /// </summary>
 /// <param name="options">The <see cref="AzureQueueOptions"/> instance to use to configure the Azure Storage Queue. Should be registered with your Dependency Injection container.</param>
 /// <exception cref="ArgumentNullException"><paramref name="options"/>.QueueName is <see langword="null" />.</exception>
 /// <exception cref="ArgumentException">The connection string you specified was not found in the ConnectionStrings collection.</exception>
 public AzureQueueMessagePublisher(IOptions <AzureQueueOptions> options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options), "Please register an AzureQueueOptions instance with your DI container.");
     }
     if (string.IsNullOrWhiteSpace(options.Value.QueueName))
     {
         throw new ArgumentNullException(nameof(options.Value.QueueName), "Please specify an Azure Storage Queue name.");
     }
     if (string.IsNullOrWhiteSpace(options.Value.StorageConnectionString))
     {
         throw new ArgumentNullException(nameof(options.Value.StorageConnectionString), "Please specify the name of the Azure Storage Connection String.");
     }
     _options = options.Value;
 }
Exemplo n.º 12
0
 public AzureQueueAdapter(
     TDataAdapter dataAdapter,
     SerializationManager serializationManager,
     IAzureStreamQueueMapper streamQueueMapper,
     ILoggerFactory loggerFactory,
     AzureQueueOptions queueOptions,
     string serviceId,
     string providerName)
 {
     this.serializationManager = serializationManager;
     this.queueOptions         = queueOptions;
     ServiceId = serviceId;
     Name      = providerName;
     this.streamQueueMapper = streamQueueMapper;
     this.dataAdapter       = dataAdapter;
     this.loggerFactory     = loggerFactory;
 }
Exemplo n.º 13
0
 public AzureQueueAdapterFactory(
     string name,
     AzureQueueOptions options,
     SimpleQueueCacheOptions cacheOptions,
     IServiceProvider serviceProvider,
     IOptions <ClusterOptions> clusterOptions,
     SerializationManager serializationManager,
     ILoggerFactory loggerFactory)
 {
     this.providerName         = name;
     this.options              = options ?? throw new ArgumentNullException(nameof(options));
     this.clusterOptions       = clusterOptions.Value;
     this.SerializationManager = serializationManager ?? throw new ArgumentNullException(nameof(serializationManager));
     this.loggerFactory        = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.dataAadaptorFactory  = () => ActivatorUtilities.GetServiceOrCreateInstance <TDataAdapter>(serviceProvider);
     this.streamQueueMapper    = new AzureStreamQueueMapper(options.QueueNames, providerName);
     this.adapterCache         = new SimpleQueueAdapterCache(cacheOptions, this.providerName, this.loggerFactory);
 }
Exemplo n.º 14
0
 private static IServiceCollection AddAzureQueueReceiver <TKey, TValue>(this IServiceCollection services, AzureQueueOptions options)
 {
     services.AddTransient <IMessageReceiver <TKey, TValue> >(x => new AzureQueueReceiver <TKey, TValue>(
                                                                  options.ConnectionString,
                                                                  options.QueueName));
     return(services);
 }
 public static IServiceCollection AddAzureQueueSender <T>(this IServiceCollection services, AzureQueueOptions options)
 {
     services.AddSingleton <IMessageSender <T> >(new AzureQueueSender <T>(
                                                     options.ConnectionString,
                                                     options.QueueNames[typeof(T).Name]));
     return(services);
 }
 public static IServiceCollection AddAzureQueueReceiver <T>(this IServiceCollection services, AzureQueueOptions options)
 {
     services.AddTransient <IMessageReceiver <T> >(x => new AzureQueueReceiver <T>(
                                                       options.ConnectionString,
                                                       options.QueueNames[typeof(T).Name]));
     return(services);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Helper method for testing. Clears all messages in all the queues used by the specified stream provider.
        /// </summary>
        /// <param name="loggerFactory">logger factory to use</param>
        /// <param name="azureQueueNames">The deployment ID hosting the stream provider.</param>
        /// <param name="queueOptions">The azure storage options.</param>
        public static async Task ClearAllUsedAzureQueues(ILoggerFactory loggerFactory, List <string> azureQueueNames, AzureQueueOptions queueOptions)
        {
            var deleteTasks = new List <Task>();

            foreach (var queueName in azureQueueNames)
            {
                var manager = new AzureQueueDataManager(loggerFactory, queueName, queueOptions);
                deleteTasks.Add(manager.ClearQueue());
            }

            await Task.WhenAll(deleteTasks);
        }
Exemplo n.º 18
0
 private static IServiceCollection AddAzureQueueSender <TKey, TValue>(this IServiceCollection services, AzureQueueOptions options)
 {
     services.AddSingleton <IMessageSender <TKey, TValue> >(new AzureQueueSender <TKey, TValue>(
                                                                options.ConnectionString,
                                                                options.QueueName));
     return(services);
 }
 /// <summary>
 /// Creates a new instance of the <see cref="AzureQueueNameResolver"/>
 /// </summary>
 /// <param name="options">The <see cref="IOptions{AzureQueueOptions}"/> instance injected from the DI container.</param>
 public AzureQueueNameResolver(IOptions <AzureQueueOptions> options)
 {
     _options = options.Value;
 }
Exemplo n.º 20
0
        public static IQueueAdapterReceiver Create(ILoggerFactory loggerFactory, string azureQueueName, AzureQueueOptions queueOptions, IQueueDataAdapter <string, IBatchContainer> dataAdapter)
        {
            if (azureQueueName == null)
            {
                throw new ArgumentNullException(nameof(azureQueueName));
            }
            if (queueOptions == null)
            {
                throw new ArgumentNullException(nameof(queueOptions));
            }
            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }

            var queue = new AzureQueueDataManager(loggerFactory, azureQueueName, queueOptions);

            return(new AzureQueueAdapterReceiver(azureQueueName, loggerFactory, queue, dataAdapter));
        }