public void DeleteQueue()
 {
     using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, _amazonSqsConfig))
     {
         client.DeleteQueue(_queueUrl);
     }
 }
Example #2
0
        private static void DeleteTopic(Topic topic)
        {
            var settings  = SettingsManager.GetSettings();
            var snsClient = new AmazonSimpleNotificationServiceClient(
                settings.AWSAccessKeyID,
                settings.AWSSecretAccessKey,
                RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

            var sqsClient = new AmazonSQSClient(
                settings.AWSAccessKeyID,
                settings.AWSSecretAccessKey,
                RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

            // Cleanup topic & queue & local file
            try { snsClient.DeleteTopic(new DeleteTopicRequest()
                {
                    TopicArn = topic.TopicARN
                }); } catch (Exception ex) { Debug.WriteLine(ex.Message); }
            try { sqsClient.DeleteQueue(new DeleteQueueRequest()
                {
                    QueueUrl = topic.QueueUrl
                }); } catch (Exception ex) { Debug.WriteLine(ex.Message); }

            // TODO Delete the errored/complete files on startup?
            File.Delete(Path.Combine(GetTempDirectory(), topic.TopicFileName));
            Debug.WriteLine($"Deleted topic {topic.TopicARN}");
            Debug.WriteLine($"Deleted topic file {topic.TopicFileName}");
        }
Example #3
0
            public void VaultLowLevel()
            {
                try
                {
                    using (var client = new AmazonGlacierClient(
                               settings.AWSAccessKeyID,
                               settings.AWSSecretAccessKey,
                               RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName)))
                    {
                        Debug.WriteLine("Setup SNS topic and SQS queue.");
                        SetupTopicAndQueue();

                        Debug.WriteLine("Retrieve Inventory List");
                        GetVaultInventory(client);
                    }
                    Debug.WriteLine("Operations successful.");
                }
                catch (AmazonGlacierException e) { Debug.WriteLine(e.Message); }
                catch (AmazonServiceException e) { Debug.WriteLine(e.Message); }
                catch (Exception e) { Debug.WriteLine(e.Message); }
                finally
                {
                    // Delete SNS topic and SQS queue.
                    snsClient.DeleteTopic(new DeleteTopicRequest()
                    {
                        TopicArn = this.topicArn
                    });
                    sqsClient.DeleteQueue(new DeleteQueueRequest()
                    {
                        QueueUrl = this.queueUrl
                    });
                }
            }
        public void delete_queue()
        {
            var response = _client.DeleteQueue(
                new DeleteQueueRequest().WithQueueUrl("https://queue.amazonaws.com/451419498740/Ellemy_CQRS_Example"));

            Console.WriteLine(response.ToXML());
        }
        public void When_obtaining_details_on_a_message_queue(string queueName, bool exists)
        {
            // Arrange
            var client = new AmazonSQSClient("access key", "secret key");

            if (exists)
            {
                client.CreateQueue(new CreateQueueRequest().WithQueueName(queueName));
            }
            else
            {
                var response = client.ListQueues(new ListQueuesRequest().WithQueueNamePrefix(queueName));
                if (response.ListQueuesResult.QueueUrl.Any())
                {
                    client.DeleteQueue(new DeleteQueueRequest().WithQueueUrl(response.ListQueuesResult.QueueUrl.First()));
                }
            }

            Thread.Sleep(2000); // Give the queues some time to spin up

            var factory = new AmazonSqsMessageQueueDetailFactory(client);


            // Act
            var result = factory.Build <TestMessage>(queueName);

            // Assert
            Assert.That(result.Uri, Is.StringContaining(queueName));
            Assert.That(result.Exists, Is.EqualTo(exists));
        }
Example #6
0
 public void DeleteQueue()
 {
     using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, _regionEndpoint))
     {
         client.DeleteQueue(_queueUrl);
     }
 }
Example #7
0
 public static void DeleteQueueByQueueUrl(string queueUrl)
 {
     using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
     {
         client.DeleteQueue(queueUrl);
     }
 }
Example #8
0
        public void DeleteQueue()
        {
            var request = new DeleteQueueRequest();

            request.QueueUrl = QueueUrl;
            _sqsClient.DeleteQueue(request);
        }
        public override void DeleteQueue()
        {
            var deleteQueueRequest = new DeleteQueueRequest();

            deleteQueueRequest.QueueUrl = Address;
            _sqsClient.DeleteQueue(deleteQueueRequest);
        }
        public override void DeleteQueue()
        {
            var deleteQueueRequest  = new DeleteQueueRequest(MessageAddress.Address);
            var deleteQueueResponse = _sqsClient.DeleteQueue(deleteQueueRequest);

            if (deleteQueueResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                // throw or log something
            }
        }
Example #11
0
        public virtual void DeleteQueue(AmazonSQSClient sqsClient, string queueUrl)
        {
            var deleteQueueRequest = new DeleteQueueRequest
            {
                QueueUrl = queueUrl
            };

            // Delete the queue
            sqsClient.DeleteQueue(deleteQueueRequest);
        }
Example #12
0
        public void DeleteQueueExample()
        {
            AmazonSQSClient client = new AmazonSQSClient();

            var request = new DeleteQueueRequest
            {
                QueueUrl = "SQS_QUEUE_URL"
            };

            client.DeleteQueue(request);
        }
Example #13
0
        /// <summary>
        /// Delete a named queue.
        /// </summary>
        /// <param name="queueName">Queue name.</param>
        /// <returns>True if the named queue was deleted</returns>
        public bool DeleteQueue(SqsQueueName queueName)
        {
            var response = Invoke(() =>
                                  _client.DeleteQueue(new DeleteQueueRequest {
                QueueUrl = GetQueueUrl(queueName.Value)
            }),
                                  queueName,
                                  DELETING_QUEUE
                                  );

            return(response.HttpStatusCode == HttpStatusCode.OK);
        }
Example #14
0
        public static void SQSDeleteQueue()
        {
            #region SQSDeleteQueue
            var client = new AmazonSQSClient();

            var request = new DeleteQueueRequest
            {
                QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue"
            };

            client.DeleteQueue(request);
            #endregion
        }
Example #15
0
        public void IsMessageSignatureValid()
        {
            string topicArn = null;
            string queueUrl = null;

            try
            {
                topicArn = CreateTopic();
                queueUrl = CreateQueue();

                SubscribeQueue(topicArn, queueUrl);
                List <Message> messages = PublishToSNSAndReceiveMessages(GetPublishRequest(topicArn), topicArn, queueUrl);

                Assert.AreEqual(1, messages.Count);
                var bodyJson = GetBodyJson(messages[0]);

                var validMessage = Amazon.SimpleNotificationService.Util.Message.ParseMessage(bodyJson);
                Assert.IsTrue(validMessage.IsMessageSignatureValid());

                var invalidMessage = Amazon.SimpleNotificationService.Util.Message.ParseMessage(bodyJson.Replace("Test Message", "Hacked Message"));
                Assert.IsFalse(invalidMessage.IsMessageSignatureValid());
            }
            finally
            {
                if (topicArn != null)
                {
                    Client.DeleteTopic(new DeleteTopicRequest {
                        TopicArn = topicArn
                    });
                }

                if (queueUrl != null)
                {
                    sqsClient.DeleteQueue(new DeleteQueueRequest {
                        QueueUrl = queueUrl
                    });
                }
            }
        }
Example #16
0
        public void DeleteQueues()
        {
            DeleteQueueRequest request = new DeleteQueueRequest {
                QueueUrl = DeleteQueue
            };
            var response = client.DeleteQueue(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine("Queue has been deleted successfully");
                Console.WriteLine("Current Queues");
                ListQueues();
            }
        }
        public void DeleteQueues()
        {
            DeleteQueueRequest request = new DeleteQueueRequest
            {
                QueueUrl = "https://sqs.us-east-1.amazonaws.com/491483104165/newappqueue"
            };

            var response = client.DeleteQueue(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine($"\nQueue has been deleted successfully");
            }
        }
Example #18
0
        public void DeleteQueue()
        {
            DeleteQueueRequest request = new DeleteQueueRequest {
                QueueUrl = "https://sqs.eu-west-1.amazonaws.com/109720996851/myAppQueue2"
            };
            var response = client.DeleteQueue(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Queue has been removed");
                ListQueues();
            }
            Console.ReadLine();
        }
Example #19
0
        public static void DeleteAllQueues()
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var response = client.ListQueues(new ListQueuesRequest());

                foreach (var queueUrl in response.QueueUrls)
                {
                    PurgeQueueByQueueUrl(queueUrl);

                    client.DeleteQueue(queueUrl);
                }
            }
        }
        static bool GetInventory(Amazon.RegionEndpoint region)
        {
            bool error = false;

            AmazonGlacierClient client;

            try
            {
                using (client = new AmazonGlacierClient(region))
                {
                    WriteLogConsole("Setup SNS topic and SQS queue.", region);
                    SetupTopicAndQueue(region);
                    WriteLogConsole("Retrieve Inventory List", region);
                    GetVaultInventory(client, region);
                }
                WriteLogConsole("Operations successful.", region);
                DisplayVaultInventory();
            }
            catch (AmazonGlacierException e)
            {
                WriteLogConsole("AmazonGlacierException: " + e.Message, region);
                error = true;
            }
            catch (AmazonServiceException e)
            {
                WriteLogConsole("AmazonServiceException: " + e.Message, region);
                error = true;
            }
            catch (Exception e)
            {
                WriteLogConsole("Exception: " + e.Message, region);
                error = true;
            }
            finally
            {
                // Delete SNS topic and SQS queue.
                s_snsClient.DeleteTopic(new DeleteTopicRequest()
                {
                    TopicArn = s_topicArn
                });
                s_sqsClient.DeleteQueue(new DeleteQueueRequest()
                {
                    QueueUrl = s_queueUrl
                });
            }

            return(error);
        }
        public void Messages_are_queued()
        {
            var client   = new AmazonSQSClient(ConfigurationManager.AppSettings["AWSKey"], ConfigurationManager.AppSettings["AWSSecret"]);
            var queue    = Guid.NewGuid().ToString();
            var consumer = new SimpleQueueConsumer <StringEvent>(client, queue);
            var block    = new AutoResetEvent(false);

            var producer = new ObservingProducer <StringEvent>();

            producer.Attach(consumer);
            producer.Produces(GetPayload().ToObservable());
            producer.Start();

            block.WaitOne(TimeSpan.FromSeconds(5));
            client.DeleteQueue(new DeleteQueueRequest().WithQueueUrl(consumer.QueueUrl));
        }
        public void Messages_are_dequeued()
        {
            var block    = new AutoResetEvent(false);
            var sent     = 10;
            var received = 0;

            var serializer = new JsonSerializer();
            var key        = ConfigurationManager.AppSettings["AWSKey"];
            var secret     = ConfigurationManager.AppSettings["AWSSecret"];
            var queueName  = Guid.NewGuid().ToString();

            var client = new AmazonSQSClient(key, secret);

            // Anything put into the queue will go to Amazon SQS
            var queue    = new ConcurrentQueue <StringEvent>();
            var consumer = new SimpleQueueConsumer <StringEvent>(client, queueName);

            new CollectionProducer <StringEvent>(queue).Consumes(consumer).Start();

            // Anything taken from Amazon SQS goes to the console
            new SimpleQueueProducer <StringEvent>(client, queueName, serializer).Consumes(new DelegatingConsumer <StringEvent>(@event =>
            {
                Console.WriteLine(@event.Text);
                received++;
                if (received >= sent)
                {
                    block.Set();
                }
            })).Start();

            // Make some messages
            queue.Enqueue(new StringEvent("Test1"));
            queue.Enqueue(new StringEvent("Test2"));
            queue.Enqueue(new StringEvent("Test3"));
            queue.Enqueue(new StringEvent("Test4"));
            queue.Enqueue(new StringEvent("Test5"));
            queue.Enqueue(new StringEvent("Test6"));
            queue.Enqueue(new StringEvent("Test7"));
            queue.Enqueue(new StringEvent("Test8"));
            queue.Enqueue(new StringEvent("Test9"));
            queue.Enqueue(new StringEvent("Test10"));

            block.WaitOne();

            client.DeleteQueue(new DeleteQueueRequest().WithQueueUrl(consumer.QueueUrl));
        }
Example #23
0
        protected void btnDeleteQueue_Click(object sender, EventArgs e)
        {
            if (QueuesList.SelectedIndex > -1)
            {
                string selectedQueue = this.QueuesList.SelectedItem.Value.ToString();
                DeleteQueueResponse queueDeleteResponse = new DeleteQueueResponse();
                queueDeleteResponse = objClient.DeleteQueue(new DeleteQueueRequest()
                {
                    QueueUrl = selectedQueue
                });

                DisplayQueues();
                Response.Write("<script>alert('Queue Deletion Request sent. It may take few seconds to Delete Queue.');</script>");
            }
            else
            {
                Response.Write("<script>alert('Please select Queue from list.');</script>");
            }
        }
Example #24
0
        public static void GetInventory(string vaultName, string jobId, string outputPath, Amazon.RegionEndpoint awsRegion)
        {
            AmazonGlacierClient client;

            try
            {
                // Get AWS account info (needed to configure the SNS queue)
                using (var iamClient = new AmazonSecurityTokenServiceClient(awsRegion))
                {
                    var identityResponse = iamClient.GetCallerIdentity(new GetCallerIdentityRequest());
                    awsAccount = identityResponse.Account;
                    accountArn = identityResponse.Arn;
                }

                Console.WriteLine("accountArn: {accountArn}");

                using (client = new AmazonGlacierClient(awsRegion))
                {
                    if (string.IsNullOrEmpty(jobId))
                    {
                        Console.WriteLine("Setup SNS topic and SQS queue.");
                        SetupTopicAndQueue(awsRegion);
                        Console.WriteLine("To continue, press Enter");
                        Console.ReadKey();

                        Console.WriteLine("Retrieve Inventory List");
                        jobId = GetVaultInventoryJobId(vaultName, client);

                        // Check queue for a message and if job completed successfully, download inventory.
                        ProcessQueue(vaultName, jobId, client, outputPath);
                    }
                    else
                    {
                        Console.WriteLine("Downloading job output");
                        DownloadOutput(vaultName, jobId, client, outputPath); // Save job output to the specified file location.
                    }
                }
                Console.WriteLine("Operations successful.");
                Console.WriteLine("To continue, press Enter");
                Console.ReadKey();
            }
            catch (AmazonGlacierException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally
            {
                // Delete SNS topic and SQS queue.
                if (!string.IsNullOrEmpty(topicArn))
                {
                    snsClient.DeleteTopic(new DeleteTopicRequest()
                    {
                        TopicArn = topicArn
                    });
                }

                if (!string.IsNullOrEmpty(queueUrl))
                {
                    sqsClient.DeleteQueue(new DeleteQueueRequest()
                    {
                        QueueUrl = queueUrl
                    });
                }
            }
        }
Example #25
0
        public void TestQueueSubscription()
        {
            // create new topic
            var topicName          = "dotnetsdkTopic" + DateTime.Now.Ticks;
            var createTopicRequest = new CreateTopicRequest
            {
                Name = topicName
            };
            var createTopicResult = Client.CreateTopic(createTopicRequest);
            var topicArn          = createTopicResult.TopicArn;

            var queueName = "dotnetsdkQueue-" + DateTime.Now.Ticks;
            var queueUrl  = sqsClient.CreateQueue(new CreateQueueRequest
            {
                QueueName = queueName
            }).QueueUrl;

            try
            {
                var subscriptionARN = Client.SubscribeQueue(topicArn, sqsClient, queueUrl);

                // Sleep to wait for the subscribe to complete.
                Thread.Sleep(TimeSpan.FromSeconds(5));

                var publishRequest = new PublishRequest
                {
                    TopicArn          = topicArn,
                    Subject           = "Test Subject",
                    Message           = "Test Message",
                    MessageAttributes = new Dictionary <string, SNSMessageAttributeValue>
                    {
                        { "Color", new SNSMessageAttributeValue {
                              StringValue = "Red", DataType = "String"
                          } },
                        { "Binary", new SNSMessageAttributeValue {
                              DataType = "Binary", BinaryValue = new MemoryStream(Encoding.UTF8.GetBytes("Yes please"))
                          } },
                        { "Prime", new SNSMessageAttributeValue {
                              StringValue = "31", DataType = "Number"
                          } },
                    }
                };
                Client.Publish(publishRequest);

                var messages = sqsClient.ReceiveMessage(new ReceiveMessageRequest
                {
                    QueueUrl        = queueUrl,
                    WaitTimeSeconds = 20
                }).Messages;

                Assert.AreEqual(1, messages.Count);
                var message = messages[0];

                string bodyJson;
                // Handle some accounts returning message body as base 64 encoded.
                if (message.Body.Trim()[0] == '{')
                {
                    bodyJson = message.Body;
                }
                else
                {
                    bodyJson = Encoding.UTF8.GetString(Convert.FromBase64String(message.Body));
                }

                var json           = ThirdParty.Json.LitJson.JsonMapper.ToObject(bodyJson);
                var messageText    = json["Message"];
                var messageSubject = json["Subject"];
                Assert.AreEqual(publishRequest.Message, messageText.ToString());
                Assert.AreEqual(publishRequest.Subject, messageSubject.ToString());
                var messageAttributes = json["MessageAttributes"];
                Assert.AreEqual(publishRequest.MessageAttributes.Count, messageAttributes.Count);
                foreach (var ma in publishRequest.MessageAttributes)
                {
                    var name  = ma.Key;
                    var value = ma.Value;
                    Assert.IsTrue(messageAttributes.PropertyNames.Contains(name, StringComparer.Ordinal));
                    var jsonAttribute = messageAttributes[name];
                    var jsonType      = jsonAttribute["Type"].ToString();
                    var jsonValue     = jsonAttribute["Value"].ToString();
                    Assert.IsNotNull(jsonType);
                    Assert.IsNotNull(jsonValue);
                    Assert.AreEqual(value.DataType, jsonType);
                    Assert.AreEqual(value.DataType != "Binary"
                                        ? value.StringValue
                                        : Convert.ToBase64String(value.BinaryValue.ToArray()), jsonValue);
                }

                sqsClient.DeleteMessage(new DeleteMessageRequest
                {
                    QueueUrl      = queueUrl,
                    ReceiptHandle = messages[0].ReceiptHandle
                });

                // This will unsubscribe but leave the policy in place.
                Client.Unsubscribe(new UnsubscribeRequest
                {
                    SubscriptionArn = subscriptionARN
                });

                // Subscribe again to see if this affects the policy.
                Client.SubscribeQueue(topicArn, sqsClient, queueUrl);

                Client.Publish(new PublishRequest
                {
                    TopicArn = topicArn,
                    Message  = "Test Message again"
                });

                messages = sqsClient.ReceiveMessage(new ReceiveMessageRequest
                {
                    QueueUrl        = queueUrl,
                    WaitTimeSeconds = 20
                }).Messages;

                Assert.AreEqual(1, messages.Count);

                var getAttributeResponse = sqsClient.GetQueueAttributes(new GetQueueAttributesRequest
                {
                    AttributeNames = new List <string> {
                        "All"
                    },
                    QueueUrl = queueUrl
                });

                var policy = Policy.FromJson(getAttributeResponse.Policy);
                Assert.AreEqual(1, policy.Statements.Count);
            }
            finally
            {
                Client.DeleteTopic(new DeleteTopicRequest {
                    TopicArn = topicArn
                });
                sqsClient.DeleteQueue(new DeleteQueueRequest {
                    QueueUrl = queueUrl
                });
            }
        }
        public void SetQueueConfigurationTests()
        {
            var filterRule = new FilterRule("Prefix", "test/");
            var s3Config   = new AmazonS3Config();

            using (var s3Client = new AmazonS3Client(s3Config))
                using (var sqsClient = new AmazonSQSClient())
                    using (var stsClient = new AmazonSecurityTokenServiceClient())
                    {
                        var createResponse = sqsClient.CreateQueue("events-test-" + DateTime.Now.Ticks);
                        var bucketName     = S3TestUtils.CreateBucketWithWait(s3Client);

                        try
                        {
                            var queueArn = sqsClient.AuthorizeS3ToSendMessage(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
                                                }
                                            }
                                        }
                                    }
                                }
                            };

                            s3Client.PutBucketNotification(putRequest);

                            var getResponse = S3TestUtils.WaitForConsistency(() =>
                            {
                                var res = s3Client.GetBucketNotification(bucketName);
                                return(res.QueueConfigurations?.Count > 0 && res.QueueConfigurations[0].Id == "the-queue-test" ? res : null);
                            });

                            var getAttributeResponse = sqsClient.GetQueueAttributes(new GetQueueAttributesRequest
                            {
                                QueueUrl       = createResponse.QueueUrl,
                                AttributeNames = new List <string> {
                                    "All"
                                }
                            });

                            var policy     = Policy.FromJson(getAttributeResponse.Policy);
                            var conditions = policy.Statements[0].Conditions;
                            Assert.AreEqual(2, conditions.Count);

                            var accountCondition = conditions.FirstOrDefault(x => string.Equals(x.ConditionKey, ConditionFactory.SOURCE_ACCOUNT_KEY));
                            Assert.IsNotNull(accountCondition);
                            Assert.AreEqual(ConditionFactory.StringComparisonType.StringEquals.ToString(), accountCondition.Type);
                            Assert.AreEqual(12, accountCondition.Values[0].Length);

                            var currentAccountId = stsClient.GetCallerIdentity(new GetCallerIdentityRequest()).Account;
                            Assert.AreEqual(currentAccountId, accountCondition.Values[0]);


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

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

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

                            // Purge queue to remove test message sent configuration was setup.
                            sqsClient.PurgeQueue(createResponse.QueueUrl);
                            //We must wait 60 seconds or the next message being sent to the queue could be deleted while the queue is being purged.
                            Thread.Sleep(TimeSpan.FromSeconds(60));

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

                            s3Client.PutObject(putObjectRequest);

                            string messageBody = null;
                            for (int i = 0; i < 5 && messageBody == null; i++)
                            {
                                var receiveResponse = sqsClient.ReceiveMessage(new ReceiveMessageRequest {
                                    QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20
                                });
                                if (receiveResponse.Messages.Count != 0)
                                {
                                    messageBody = receiveResponse.Messages[0].Body;
                                }
                            }


                            var evnt = S3EventNotification.ParseJson(messageBody);

                            Assert.AreEqual(1, evnt.Records.Count);
                            Assert.AreEqual(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name);
                            Assert.AreEqual(putObjectRequest.Key, evnt.Records[0].S3.Object.Key);
                            Assert.AreEqual(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size);
                            Assert.IsNotNull(evnt.Records[0].S3.Object.Sequencer);
                        }
                        finally
                        {
                            sqsClient.DeleteQueue(createResponse.QueueUrl);
                            AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                        }
                    }
        }
Example #27
0
        public void SetQueueConfigurationTests()
        {
            var filterRule = new FilterRule("Prefix", "test/");
            var s3Config   = new AmazonS3Config();

            using (var s3Client = new AmazonS3Client(s3Config))
                using (var sqsClient = new AmazonSQSClient())
                {
                    var createResponse = sqsClient.CreateQueue("events-test-" + DateTime.Now.Ticks);
                    var bucketName     = S3TestUtils.CreateBucket(s3Client);
                    try
                    {
                        var queueArn = sqsClient.AuthorizeS3ToSendMessage(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
                                            }
                                        }
                                    }
                                }
                            }
                        };

                        s3Client.PutBucketNotification(putRequest);

                        var getResponse = s3Client.GetBucketNotification(bucketName);

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

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

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

                        // Purge queue to remove test message sent configuration was setup.
                        sqsClient.PurgeQueue(createResponse.QueueUrl);
                        Thread.Sleep(TimeSpan.FromSeconds(1));

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

                        s3Client.PutObject(putObjectRequest);

                        string messageBody = null;
                        for (int i = 0; i < 5 && messageBody == null; i++)
                        {
                            var receiveResponse = sqsClient.ReceiveMessage(new ReceiveMessageRequest {
                                QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20
                            });
                            if (receiveResponse.Messages.Count != 0)
                            {
                                messageBody = receiveResponse.Messages[0].Body;
                            }
                        }


                        var evnt = S3EventNotification.ParseJson(messageBody);

                        Assert.AreEqual(1, evnt.Records.Count);
                        Assert.AreEqual(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name);
                        Assert.AreEqual(putObjectRequest.Key, evnt.Records[0].S3.Object.Key);
                        Assert.AreEqual(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size);
                        Assert.IsNotNull(evnt.Records[0].S3.Object.Sequencer);
                    }
                    finally
                    {
                        sqsClient.DeleteQueue(createResponse.QueueUrl);
                        AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                    }
                }
        }
Example #28
0
 public static void DeleteQueue(string queueUrl, AmazonSQSClient sqsClient)
 {
     sqsClient.DeleteQueue(new DeleteQueueRequest(queueUrl));
 }