protected async Task InvokeAsync()
        {
            var sqsClient    = AwsClientsSingletonsProvider.GetSqsClient();
            var queueService = new QueueService(sqsClient);

            await queueService.AddMessageAsync(new ItemMessage(Guid.NewGuid()), GetQueueUrl());
        }
예제 #2
0
        public async Task VerifyQueueService_AddMessage_GetMessage_DeleteMessage()
        {
            // Arrange
            IQueueService queueService = new QueueService("UseDevelopmentStorage=true", "testqueue");

            // Act
            await queueService.AddMessageAsync("test");

            var message = await queueService.GetMessageAsync();

            // Assert
            Assert.IsNotNull(queueService);
            Assert.IsNotNull(message);

            // Cleanup
            await queueService.DeleteMessageAsync(message);
        }
예제 #3
0
        protected override async Task HandleAsync(AddItemLambdaRequest lambdaRequest)
        {
            var newItem = lambdaRequest.ToNewItem();

            var s3Client     = AwsClientsSingletonsProvider.GetS3Client();
            var s3Config     = ConfigurationReader.GetS3Config();
            var s3Repository = new S3Repository(s3Client, s3Config);
            await s3Repository.PutNewItemAsync(newItem);

            Logger.Log("New item saved", "INFO");

            var sqsClient    = AwsClientsSingletonsProvider.GetSqsClient();
            var queueService = new QueueService(sqsClient, ConfigurationReader.GetSqsConfig());
            await queueService.AddMessageAsync(new ItemMessage(newItem.Id));

            Logger.Log("New item added event sent", "INFO");
        }
예제 #4
0
 protected virtual async Task DeleteAsync(string id)
 {
     try
     {
         ICommand command = new DeleteGenericObjectCommand <TDocument>(this.CurrentTenant.Name, id);
         await QueueService.AddMessageAsync(command);
     }
     catch (HttpResponseException ex)
     {
         ElmahLogger.LogError(ex);
         throw;
     }
     catch (Exception ex)
     {
         ElmahLogger.LogError(ex);
         throw new HttpResponseException(HttpStatusCode.InternalServerError);
     }
 }
예제 #5
0
        public static async Task Main(string[] args)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Producer - adding messages to Azure queue 250 ms.");
            Console.CancelKeyPress += Console_CancelKeyPress;
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Press CTRL+C to stop the producer adding queue messages.");
            Console.WriteLine();

            // Using a SAS Key that is valid for a fixed period only.
            // "Connection String" value when Generare SAS and connection string button in Azure
            // OR - use from app.config "appSettings" -> AzureQueueStorageConnectionString
            var connectionString = CloudConfigurationManager.GetSetting("AzureQueueStorageConnectionString");

            var           messagesAdded = 0;
            IQueueService queueService  = new QueueService(connectionString, "samplequeue");

            while (!cancelProducer)
            {
                var message = string.Format("Sample message at {0}", DateTime.Now.ToUniversalTime());
                await queueService.AddMessageAsync(message);

                messagesAdded++;
                Console.SetCursorPosition(0, 4);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Messages added: " + messagesAdded.ToString());
                Console.SetCursorPosition(0, 5);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Added to queue: " + message);
                Thread.Sleep(250);
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
            Console.WriteLine("Completed. Press a key to exit.");
            Console.ReadKey();
        }
예제 #6
0
        protected virtual async Task ReplaceAsync(string id, TDocument item)
        {
            if (item == null || !this.ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            try
            {
                ICommand command = new ReplaceGenericObjectCommand <TDocument>(this.CurrentTenant.Name, item);
                await QueueService.AddMessageAsync(command);
            }
            catch (HttpResponseException ex)
            {
                ElmahLogger.LogError(ex);
                throw;
            }
            catch (Exception ex)
            {
                ElmahLogger.LogError(ex);
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
예제 #7
0
        public async Task VerifyQueueService_Add10Messages_Get5Messages_DeleteMessages()
        {
            // Arrange
            IQueueService queueService = new QueueService("UseDevelopmentStorage=true", "testqueue");

            // Act
            for (var messageCount = 0; messageCount < 10; messageCount++)
            {
                await queueService.AddMessageAsync("test " + messageCount.ToString());
            }

            var messages = await queueService.GetMessagesAsync(5, TimeSpan.FromHours(1));

            // Assert
            Assert.IsNotNull(queueService);
            Assert.IsNotNull(messages);
            Assert.AreEqual(5, messages.Count());

            // Cleanup
            foreach (var message in messages)
            {
                await queueService.DeleteMessageAsync(message);
            }
        }