Пример #1
0
        public async Task TestPurgeQueueAsync()
        {
            // Create the queue
            queueName = setQueueName();
            queueURL  = createQueueURLAsync(queueName);

            // Send message
            var request = new SendMessageRequest(queueURL.Result.ToString(), messageBody);
            await sqsClient.SendMessageAsync(request);

            var receiveResponse = sqsClient.ReceiveMessageAsync(queueURL.Result.ToString());

            Assert.IsTrue(receiveResponse.Result.Messages.Count == 1, "Message is not created");

            // Purge the queue
            await sqsClient.PurgeQueueAsync(queueURL.Result.ToString());

            // Verify the message is no longer in the queue
            receiveResponse = sqsClient.ReceiveMessageAsync(queueURL.Result.ToString());
            Assert.IsTrue(receiveResponse.Result.Messages.Count == 0, "Message is not deleted");
        }
Пример #2
0
        private async Task <string> SqsRequest(string request)
        {
            // Purge the queue which we will later listen to for responses
            var sqsClient = new AmazonSQSClient(RegionEndpoint.EUWest1);

            try
            {
                await sqsClient.PurgeQueueAsync(SqsServerUri);
            }
            catch (PurgeQueueInProgressException)
            {
                // This happens if we try to purge the queue twice in 60 seconds. Safe to ignore since this is a "just in case" purge
            }

            // Send the request to the client
            await sqsClient.SendMessageAsync(SqsClientUri, request);

            // Wait for a response
            var receiveRequest = new ReceiveMessageRequest(SqsServerUri);

            receiveRequest.MaxNumberOfMessages = 1;
            receiveRequest.VisibilityTimeout   = 60;
            receiveRequest.WaitTimeSeconds     = 20;
            var responses = await sqsClient.ReceiveMessageAsync(receiveRequest);

            if (responses.Messages.Count == 1)
            {
                var message = responses.Messages[0];

                // delete the message from the queue
                await sqsClient.DeleteMessageAsync(SqsServerUri, message.ReceiptHandle);

                return(message.Body);
            }
            else
            {
                return("The sphero service did not respond");
            }
        }
Пример #3
0
        public async Task SetQueueConfigurationTests()
        {
            var filterRule = new FilterRule("Prefix", "test/");

            using (var sqsClient = new AmazonSQSClient())
            {
                string topicName      = UtilityMethods.GenerateName("events-test");
                var    createResponse = await sqsClient.CreateQueueAsync(topicName);

                var bucketName = await UtilityMethods.CreateBucketAsync(Client, "SetQueueConfigurationTests");

                try
                {
                    var queueArn = await sqsClient.AuthorizeS3ToSendMessageAsync(createResponse.QueueUrl, bucketName);

                    PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest
                    {
                        BucketName          = bucketName,
                        QueueConfigurations = new List <QueueConfiguration>
                        {
                            new QueueConfiguration
                            {
                                Id     = "the-queue-test",
                                Queue  = queueArn,
                                Events = { EventType.ObjectCreatedPut },
                                Filter = new Filter
                                {
                                    S3KeyFilter = new S3KeyFilter
                                    {
                                        FilterRules = new List <FilterRule>
                                        {
                                            filterRule
                                        }
                                    }
                                }
                            }
                        }
                    };

                    await Client.PutBucketNotificationAsync(putRequest);

                    var getResponse = await Client.GetBucketNotificationAsync(bucketName);

                    Assert.Equal(1, getResponse.QueueConfigurations.Count);
                    Assert.Equal(1, getResponse.QueueConfigurations[0].Events.Count);
                    Assert.Equal(EventType.ObjectCreatedPut, getResponse.QueueConfigurations[0].Events[0]);

                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter);
                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter);
                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules);
                    Assert.Equal(1, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules.Count);
                    Assert.Equal(filterRule.Name, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Name);
                    Assert.Equal(filterRule.Value, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Value);

                    Assert.Equal("the-queue-test", getResponse.QueueConfigurations[0].Id);
                    Assert.Equal(queueArn, getResponse.QueueConfigurations[0].Queue);

                    // Purge queue to remove test message sent configuration was setup.
                    await sqsClient.PurgeQueueAsync(createResponse.QueueUrl);

                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    var putObjectRequest = new PutObjectRequest
                    {
                        BucketName  = bucketName,
                        Key         = "test/data.txt",
                        ContentBody = "Important Data"
                    };

                    await Client.PutObjectAsync(putObjectRequest);

                    string messageBody = null;
                    for (int i = 0; i < 5 && messageBody == null; i++)
                    {
                        var receiveResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20 });

                        if (receiveResponse.Messages.Count != 0)
                        {
                            messageBody = receiveResponse.Messages[0].Body;
                        }
                    }


                    var evnt = S3EventNotification.ParseJson(messageBody);

                    Assert.Equal(1, evnt.Records.Count);
                    Assert.Equal(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name);
                    Assert.Equal(putObjectRequest.Key, evnt.Records[0].S3.Object.Key);
                    Assert.Equal(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size);
                }
                finally
                {
                    await sqsClient.DeleteQueueAsync(createResponse.QueueUrl);

                    await UtilityMethods.DeleteBucketWithObjectsAsync(Client, bucketName);
                }
            }
        }
Пример #4
0
 public void Purge(string queueUrl)
 {
     _client.PurgeQueueAsync(_queueUrl).Wait();
 }
Пример #5
0
 public static async Task Clear(string streamName)
 {
     var client = new AmazonSQSClient(creds, config);
     await client.PurgeQueueAsync(streamName);
 }
Пример #6
0
 public Task Purge()
 {
     return(Client.PurgeQueueAsync(new PurgeQueueRequest {
         QueueUrl = QueueUrl
     }));
 }