Esempio n. 1
0
 public ResetWork(ResetOptions opts_in)
 {
     opts = opts_in;
     AzureServiceFactory.Init(opts.WorkerCount);
     folderDoneSet   = AzureServiceFactory.GetFolderDoneSet();
     LargeFilesQueue = AzureServiceFactory.GetLargeFilesQueue();
 }
Esempio n. 2
0
        public async Task InitializeAsync()
        {
            FulcrumApplicationHelper.UnitTestSetup(nameof(AzureStorageV12QueueTest));
            var connectionString = TestSettings.ConnectionString;

            Assert.IsNotNull(connectionString);
            _queue = new AzureStorageQueue <Message>(connectionString, "test-queue");
            await _queue.ClearAsync();
        }
        public void ExcuteCommandNewQueueTest()
        {
            string name = "queuename";

            command.Name = name;
            command.ExecuteCmdlet();
            AzureStorageQueue queue = (AzureStorageQueue)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.AreEqual(name, queue.Name);
        }
 public async Task <IAzureStorageQueue <T> > BuildAsync()
 {
     return(await AzureStorageQueue <T>
            .CreateAsync(_settings,
                         _messageTimeoutPolicy,
                         _poisonMessageBehaviorPolicy,
                         _customStringSerializer,
                         _customBinarySerializer)
            .ConfigureAwait(false));
 }
 public IAzureStorageQueue <T> Build()
 {
     return(AzureStorageQueue <T>
            .CreateAsync(_settings,
                         _messageTimeoutPolicy,
                         _poisonMessageBehaviorPolicy,
                         _customStringSerializer,
                         _customBinarySerializer)
            .Result);
 }
Esempio n. 6
0
            public TestE()
            {
                _loader = new MessageLoader();

                azureStorageQueue = new AzureStorageQueue <string>(_loader);

                azureStorageQueue.TotalMessages = numberOfMessages;

                Run().Wait();
            }
Esempio n. 7
0
        public async Task InitializeNonExistingAsync()
        {
            var connectionString = TestSettings.ConnectionStringNonExisting;

            Assert.IsNotNull(connectionString);
            var queue = new AzureStorageQueue <Message>(connectionString, "test-queue", new QueueClientOptions
            {
                Retry = { MaxRetries = 0 }
            });
            await queue.ClearAsync();
        }
        public void ExecuteCommandGetQueueTest()
        {
            AddTestQueues();
            command.Name = "test";
            command.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);

            AzureStorageQueue queue = (AzureStorageQueue)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.AreEqual(command.Name, queue.Name);
        }
Esempio n. 9
0
        public async Task InitializeNonExistingAsync()
        {
            var connectionString = TestSettings.ConnectionStringNonExisting;

            Assert.IsNotNull(connectionString);
            var queue = new AzureStorageQueue <Message>(connectionString, "test-queue", new QueueRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromMilliseconds(500)
            });
            await queue.ClearAsync();
        }
        public void CreateAzureQueueSuccessfullyTest()
        {
            ((MockCommandRuntime)command.CommandRuntime).ResetPipelines();
            string            name  = "test";
            AzureStorageQueue queue = command.CreateAzureQueue(name);

            Assert.AreEqual("test", queue.Name);

            ((MockCommandRuntime)command.CommandRuntime).ResetPipelines();
            AssertThrows <ResourceAlreadyExistException>(() => command.CreateAzureQueue(name),
                                                         String.Format(Resources.QueueAlreadyExists, name));
        }
        public void Add_Medicamento_Dequeue()
        {
            var _commandHandler = new CommandHandler(
                new Domain.Services.MedicamentoService(
                    new MedicamentoRepository(
                        new MedicamentoContext()
                        )
                    )
                );

            var queue   = new AzureStorageQueue();
            var message = queue.DequeueAsync(AddMedicamentoCommand.ConstQueueName).Result;

            var command = JsonConvert.DeserializeObject <AddMedicamentoCommand>(message);

            _commandHandler.Handle(command);
        }
        /// <summary>
        /// write azure queue with message count
        /// </summary>
        /// <param name="queueList">An enumerable collection of CloudQueue objects</param>
        internal void WriteQueueWithCount(IEnumerable <CloudQueue> queueList)
        {
            if (null == queueList)
            {
                return;
            }

            QueueRequestOptions requestOptions = RequestOptions;

            foreach (CloudQueue queue in queueList)
            {
                //get message count
                Channel.FetchAttributes(queue, requestOptions, OperationContext);
                AzureStorageQueue azureQueue = new AzureStorageQueue(queue);

                WriteObjectWithStorageContext(azureQueue);
            }
        }
        public override IBatchReceiverQueue <Item> Create(params Item[] items)
        {
            var connectionString = "";
            var queueName        = "batchitems";

            DeleteQueueAsync(connectionString, queueName).Wait();

            var queue = new AzureStorageQueue <Item>(
                connectionString,
                queueName,
                new JsonItemSerializer());

            using (var cts = new CancellationTokenSource(30000))
            {
                foreach (var item in items)
                {
                    queue.EnqueueAsync(item, cts.Token).Wait();
                }
            }

            return(queue);
        }
        public override IBatchReceiverQueue <Item> Create(params Item[] items)
        {
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=hmgblipqueues2;AccountKey=MRD1bZv3MS85tdTES6peXFXl0n2MSZJomihKQpEGuOcWVkvRu0Bnnr5H6UPhtFQ00hQ17GI7NQ7yxRmepYQeJw==;EndpointSuffix=core.windows.net";
            var queueName        = "batchitems";

            DeleteQueueAsync(connectionString, queueName).Wait();

            var queue = new AzureStorageQueue <Item>(
                connectionString,
                queueName,
                new JsonItemSerializer());

            using (var cts = new CancellationTokenSource(30000))
            {
                foreach (var item in items)
                {
                    queue.EnqueueAsync(item, cts.Token).Wait();
                }
            }

            return(queue);
        }
 /// <summary>
 /// Initializes Azure Queue Workitem mgmt
 /// </summary>
 /// <param name="account">CloudStorageAccount</param>
 /// <param name="queueName">Queue Name</param>
 /// <param name="largeFiles">Is this large file processing?</param>
 internal AzureQueueWorkItemMgmt(string queueName, bool largeFiles)
 {
     azureStorageQueue = AzureServiceFactory.ConnectToAzureStorageQueue(queueName, largeFiles);
 }
Esempio n. 16
0
        public static ServiceOptions AddSampleCustomers(
            this ServiceOptions options,
            string section = "naos:sample:customers")
        {
            EnsureArg.IsNotNull(options, nameof(options));
            EnsureArg.IsNotNull(options.Context, nameof(options.Context));

            options.Context.AddTag("Customers");
            options.Context.AddServiceClient <UserAccountsClient>();

            var cosmosDbConfiguration = options.Context.Configuration?.GetSection($"{section}:cosmosDb").Get <CosmosDbConfiguration>();

            options.Context.Services.AddScoped <ICustomerRepository>(sp =>
            {
                return(new CustomerRepository(
                           new RepositoryLoggingDecorator <Customer>(
                               sp.GetRequiredService <ILogger <CustomerRepository> >(),
                               new RepositoryTenantDecorator <Customer>(
                                   "naos_sample_test",
                                   new CosmosDbSqlRepository <Customer>(o => o
                                                                        .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                                        .Mediator(sp.GetRequiredService <IMediator>())
                                                                        .Provider(new CosmosDbSqlProviderV2 <Customer>(
                                                                                      logger: sp.GetRequiredService <ILogger <CosmosDbSqlProviderV2 <Customer> > >(),
                                                                                      client: CosmosDbClientV2.Create(cosmosDbConfiguration.ServiceEndpointUri, cosmosDbConfiguration.AuthKeyOrResourceToken),
                                                                                      databaseId: cosmosDbConfiguration.DatabaseId,
                                                                                      collectionIdFactory: () => cosmosDbConfiguration.CollectionId,
                                                                                      partitionKeyPath: cosmosDbConfiguration.CollectionPartitionKey,
                                                                                      throughput: cosmosDbConfiguration.CollectionOfferThroughput,
                                                                                      isMasterCollection: cosmosDbConfiguration.IsMasterCollection)))))));
            });

            options.Context.Services.AddScoped <ICosmosDbSqlProvider <Customer> >(sp =>
            {
                return(new CosmosDbSqlProviderV3 <Customer>(o => o
                                                            .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                            .Account(cosmosDbConfiguration.ServiceEndpointUri, cosmosDbConfiguration.AuthKeyOrResourceToken)
                                                            .Database(cosmosDbConfiguration.DatabaseId)));
            });

            var queueStorageConfiguration = options.Context.Configuration?.GetSection($"{section}:queueStorage").Get <QueueStorageConfiguration>();

            options.Context.Services.AddSingleton <IQueue>(sp =>
            {
                var q1 = new AzureStorageQueue <Customer>(
                    new AzureStorageQueueOptionsBuilder()
                    .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                    .ConnectionString(queueStorageConfiguration.ConnectionString).Build());
                _ = q1.EnqueueAsync(new Customer()).Result;
                _ = q1.EnqueueAsync(new Customer()).Result;
                return(q1);
            });

            options.Context.Services
            .AddHealthChecks()
            .AddAzureQueueStorage(
                queueStorageConfiguration.ConnectionString,
                name: "Customers-queueStorage");

            //options.Context.Services.AddSingleton<IValidator<CreateCustomerCommand>>(new CreateCustomerCommandValidator());

            options.Context.Services
            .AddHealthChecks()
            .AddDocumentDb(s =>
            {
                s.UriEndpoint = cosmosDbConfiguration.ServiceEndpointUri;
                s.PrimaryKey  = cosmosDbConfiguration.AuthKeyOrResourceToken;
            },
                           name: "Customers-cosmosdb")
            .AddServiceDiscoveryClient <UserAccountsClient>();

            options.Context.Messages.Add($"{LogKeys.Startup} naos services builder: customers service added");

            return(options);
        }
        /// <summary>
        /// write azure queue with message count
        /// </summary>
        /// <param name="queueList">An enumerable collection of CloudQueue objects</param>
        internal void WriteQueueWithCount(IEnumerable<CloudQueue> queueList)
        {
            if (null == queueList)
            {
                return;
            }

            QueueRequestOptions requestOptions = RequestOptions;
            
            foreach (CloudQueue queue in queueList)
            {
                //get message count
                Channel.FetchAttributes(queue, requestOptions, OperationContext);
                AzureStorageQueue azureQueue = new AzureStorageQueue(queue);

                WriteObjectWithStorageContext(azureQueue);
            }
        }
Esempio n. 18
0
        public override void ExecuteCmdlet()
        {
            AzureStorageQueue azureQueue = CreateAzureQueue(Name);

            WriteObjectWithStorageContext(azureQueue);
        }
Esempio n. 19
0
        public static ModuleOptions AddCustomersModule(
            this ModuleOptions options,
            string section = "naos:sample:customers")
        {
            EnsureArg.IsNotNull(options, nameof(options));
            EnsureArg.IsNotNull(options.Context, nameof(options.Context));

            options.Context.AddTag("customers"); // TODO: discover (how?) alle aggregates for this module
            options.Context.AddServiceClient <UserAccountsClient>();

            var configuration = options.Context.Configuration?.GetSection($"{section}:cosmosDb").Get <CosmosConfiguration>() ?? new CosmosConfiguration();

            options.Context.Services.AddScoped <ICustomerRepository>(sp =>
            {
                return(new CustomerRepository(
                           new RepositoryTracingDecorator <Customer>(
                               sp.GetService <ILogger <CustomerRepository> >(),
                               sp.GetService <ITracer>(),
                               new RepositoryLoggingDecorator <Customer>(
                                   sp.GetRequiredService <ILogger <CustomerRepository> >(),
                                   new RepositoryTenantDecorator <Customer>(
                                       "naos_sample_test",
                                       new CosmosSqlRepository <Customer>(o => o
                                                                          .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                                          .Mediator(sp.GetRequiredService <IMediator>())
                                                                          .Provider(sp.GetRequiredService <ICosmosSqlProvider <Customer> >()))))))); // v3
                                                                                                                                                     //.Provider(new CosmosDbSqlProviderV2<Customer>( // v2
                                                                                                                                                     //    logger: sp.GetRequiredService<ILogger<CosmosDbSqlProviderV2<Customer>>>(),
                                                                                                                                                     //    client: CosmosDbClientV2.Create(cosmosDbConfiguration.ServiceEndpointUri, cosmosDbConfiguration.AuthKeyOrResourceToken),
                                                                                                                                                     //    databaseId: cosmosDbConfiguration.DatabaseId,
                                                                                                                                                     //    collectionIdFactory: () => cosmosDbConfiguration.CollectionId,
                                                                                                                                                     //    partitionKeyPath: cosmosDbConfiguration.CollectionPartitionKey,
                                                                                                                                                     //    throughput: cosmosDbConfiguration.CollectionOfferThroughput,
                                                                                                                                                     //    isMasterCollection: cosmosDbConfiguration.IsMasterCollection)))))));
            }).AddScoped <ICosmosSqlProvider <Customer> >(sp =>
            {
                return(new CosmosSqlProviderV3 <Customer>(o => o
                                                          .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                          .Account(configuration.ServiceEndpointUri, configuration.AuthKeyOrResourceToken)
                                                          .Database(configuration.DatabaseId)
                                                          .PartitionKey(e => e.Region)));
            }).AddHealthChecks()
            .AddDocumentDb(s =>
            {
                s.UriEndpoint = configuration.ServiceEndpointUri;
                s.PrimaryKey  = configuration.AuthKeyOrResourceToken;
            },
                           name: $"{typeof(Customer).Name.Pluralize()}-cosmosdb");

            options.Context.Services.AddScoped <IOrderRepository>(sp =>
            {
                return(new OrderRepository(
                           new RepositoryTracingDecorator <Order>(
                               sp.GetService <ILogger <OrderRepository> >(),
                               sp.GetService <ITracer>(),
                               new RepositoryLoggingDecorator <Order>(
                                   sp.GetRequiredService <ILogger <OrderRepository> >(),
                                   new RepositoryTenantDecorator <Order>(
                                       "naos_sample_test",
                                       new CosmosSqlRepository <Order, DtoOrder>(o => o
                                                                                 .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                                                 .Mediator(sp.GetRequiredService <IMediator>())
                                                                                 .Provider(sp.GetRequiredService <ICosmosSqlProvider <DtoOrder> >())
                                                                                 .Mapper(new AutoMapperEntityMapper(MapperFactory.Create())))))))); // v3
            }).AddScoped <ICosmosSqlProvider <DtoOrder> >(sp =>
            {
                return(new CosmosSqlProviderV3 <DtoOrder>(o => o
                                                          .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                          .Account(configuration.ServiceEndpointUri, configuration.AuthKeyOrResourceToken)
                                                          .Database(configuration.DatabaseId)
                                                          .Container(typeof(Order).Name.Pluralize().ToLower())
                                                          .PartitionKey(e => e.Location)));
            }).AddHealthChecks()
            .AddDocumentDb(s =>
            {
                s.UriEndpoint = configuration.ServiceEndpointUri;
                s.PrimaryKey  = configuration.AuthKeyOrResourceToken;
            },
                           name: $"{typeof(Order).Name.Pluralize()}-cosmosdb");

            options.Context.Services.AddSeederStartupTask <Customer, ICustomerRepository>(new[]
            {
                new Customer()
                {
                    Id = "100fb10f-2ad4-4bd1-9b33-6410a5ce1b25", Email = "*****@*****.**", TenantId = "naos_sample_test", Gender = "Male", CustomerNumber = "AB-10010", FirstName = "John", LastName = "Doe", Region = "East"
                },
                new Customer()
                {
                    Id = "100fb10f-2ad4-4bd1-9b33-6410a5ce1b26", Email = "*****@*****.**", TenantId = "naos_sample_test", Gender = "Female", CustomerNumber = "AB-10020", FirstName = "Lisa", LastName = "Doe", Region = "West"
                },
                new Customer()
                {
                    Id = "100fb10f-2ad4-4bd1-9b33-6410a5ce1b27", Email = "*****@*****.**", TenantId = "naos_sample_test", Gender = "Male", CustomerNumber = "AB-10030", FirstName = "Paul", LastName = "Doe", Region = "East"
                },
            }, delay: new TimeSpan(0, 0, 10));

            var queueStorageConfiguration = options.Context.Configuration?.GetSection($"{section}:queueStorage").Get <QueueStorageConfiguration>();

            options.Context.Services.AddSingleton <IQueue <Customer> >(sp =>
            {
                var queue = new AzureStorageQueue <Customer>(
                    new AzureStorageQueueOptionsBuilder()
                    .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                    .ConnectionString(queueStorageConfiguration.ConnectionString).Build());

                // for testing enqueue some items
                _ = queue.EnqueueAsync(new Customer()).Result;
                _ = queue.EnqueueAsync(new Customer()).Result;
                return(queue);
            });

            options.Context.Services.AddHealthChecks()
            .AddAzureQueueStorage(
                queueStorageConfiguration.ConnectionString,
                name: "Customers-azurequeuestorage");

            //options.Context.Services.AddSingleton<IValidator<CreateCustomerCommand>>(new CreateCustomerCommandValidator());
            options.Context.Messages.Add("naos services builder: customers service added");

            return(options);
        }