Amazon.SQS.AmazonSQSClient.PurgeQueue C# (CSharp) Méthode

PurgeQueue() public méthode

Deletes the messages in a queue specified by the QueueURL parameter.

When you use the PurgeQueue action, you can't retrieve a message deleted from a queue.

When you purge a queue, the message deletion process takes up to 60 seconds. All messages sent to the queue before calling the PurgeQueue action are deleted. Messages sent to the queue while it is being purged might be deleted. While the queue is being purged, messages sent to the queue before PurgeQueue is called might be received, but are deleted within the next minute.

/// Indicates that the specified queue previously received a PurgeQueue request /// within the last 60 seconds (the time it can take to delete the messages in the queue). /// /// The queue referred to doesn't exist. ///
public PurgeQueue ( PurgeQueueRequest request ) : PurgeQueueResponse
request Amazon.SQS.Model.PurgeQueueRequest Container for the necessary parameters to execute the PurgeQueue service method.
Résultat PurgeQueueResponse
        public PurgeQueueResponse PurgeQueue(PurgeQueueRequest request)
        {
            var marshaller = new PurgeQueueRequestMarshaller();
            var unmarshaller = PurgeQueueResponseUnmarshaller.Instance;

            return Invoke<PurgeQueueRequest,PurgeQueueResponse>(request, marshaller, unmarshaller);
        }

Same methods

AmazonSQSClient::PurgeQueue ( string queueUrl ) : PurgeQueueResponse

Usage Example

        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);
                }
                finally
                {
                    sqsClient.DeleteQueue(createResponse.QueueUrl);
                    AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                }
            }
        }
All Usage Examples Of Amazon.SQS.AmazonSQSClient::PurgeQueue
AmazonSQSClient