SetQueueAttributes() public méthode

Sets the value of one or more queue attributes. When you change a queue's attributes, the change can take up to 60 seconds for most of the attributes to propagate throughout the Amazon SQS system. Changes made to the MessageRetentionPeriod attribute can take up to 15 minutes.

In the future, new attributes might be added. If you write code that calls this action, we recommend that you structure your code so that it can handle new attributes gracefully.

/// The attribute referred to doesn't exist. ///
public SetQueueAttributes ( SetQueueAttributesRequest request ) : Amazon.SQS.Model.SetQueueAttributesResponse
request Amazon.SQS.Model.SetQueueAttributesRequest Container for the necessary parameters to execute the SetQueueAttributes service method.
Résultat Amazon.SQS.Model.SetQueueAttributesResponse
Exemple #1
0
    public static void SQSSetQueueAttributes()
    {
      #region SQSSetQueueAttributes
      var client = new AmazonSQSClient();

      var attrs = new Dictionary<string, string>();

      // Maximum message size of 128 KiB (1,024 bytes * 128 KiB = 131,072 bytes).
      int maxMessage = 128 * 1024;

      attrs.Add(QueueAttributeName.DelaySeconds,
        TimeSpan.FromSeconds(5).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.MaximumMessageSize, maxMessage.ToString());
      attrs.Add(QueueAttributeName.MessageRetentionPeriod,
        TimeSpan.FromDays(1).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.ReceiveMessageWaitTimeSeconds,
        TimeSpan.FromSeconds(5).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.VisibilityTimeout,
        TimeSpan.FromHours(1).TotalSeconds.ToString());
      // Dead-letter queue attributes.
      attrs.Add(QueueAttributeName.RedrivePolicy,
        "{\"maxReceiveCount\":" +
        "\"5\"," +
        "\"deadLetterTargetArn\":" +
        "\"arn:aws:sqs:us-east-1:80398EXAMPLE:MyTestDeadLetterQueue\"}");

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

      client.SetQueueAttributes(request);
      #endregion
    }
        public virtual void GrantNotificationPermission(AmazonSQSClient sqsClient, string queueArn, string queueUrl,
            string topicArn)
        {
            // Create a policy to allow the queue to receive notifications from the SNS topic
            var policy = new Policy("SubscriptionPermission")
            {
                Statements =
                {
                    new Statement(Statement.StatementEffect.Allow)
                    {
                        Actions = {SQSActionIdentifiers.SendMessage},
                        Principals = {new Principal("*")},
                        Conditions = {ConditionFactory.NewSourceArnCondition(topicArn)},
                        Resources = {new Resource(queueArn)}
                    }
                }
            };

            var attributes = new Dictionary<string, string>();
            attributes.Add("Policy", policy.ToJson());

            // Create the request to set the queue attributes for policy
            var setQueueAttributesRequest = new SetQueueAttributesRequest
            {
                QueueUrl = queueUrl,
                Attributes = attributes
            };

            // Set the queue policy
            sqsClient.SetQueueAttributes(setQueueAttributesRequest);
        }
        public void MessageDeleted()
        {
            AddConfigValue("SQSWindow", "0.00:00:15");

            int visibilityTimeout = -1;
            // change the visibility timeout of the queue
            using (Amazon.SQS.AmazonSQSClient client = new AmazonSQSClient(
                ConfigurationManager.AppSettings["AWSAccessKey"],
                ConfigurationManager.AppSettings["AWSSecretAccessKey"],
                new AmazonSQSConfig()))
            {
                // store the visibilitytimeout so we can reset it
                GetQueueAttributesRequest getRequest = new GetQueueAttributesRequest();
                getRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                getRequest.AttributeName.Add("VisibilityTimeout");
                GetQueueAttributesResponse response = client.GetQueueAttributes(getRequest);
                visibilityTimeout = response.GetQueueAttributesResult.VisibilityTimeout;

                // set it to 1 second
                SetQueueAttributesRequest setRequest = new SetQueueAttributesRequest();
                setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = "1" });
                client.SetQueueAttributes(setRequest);

                String[] messageIds = new String[] { QueueMessage() };
                MockSQSService service = new MockSQSService();
                service.Start();
                PollForMessages(messageIds, service);

                ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest();
                receiveRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                ReceiveMessageResponse receiveResponse = client.ReceiveMessage(receiveRequest);

                Assert.AreEqual(0, receiveResponse.ReceiveMessageResult.Message.Where((m) => m.MessageId == messageIds[0]).Count());

                // set the visibility timeout back
                setRequest = new SetQueueAttributesRequest();
                setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = visibilityTimeout.ToString() });
                client.SetQueueAttributes(setRequest);

                RemoveConfigValue("SQSWindow");
            }
        }