当前位置: 首页>>代码示例>>C#>>正文


C# AmazonSQSClient.SetQueueAttributes方法代码示例

本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.SetQueueAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.SetQueueAttributes方法的具体用法?C# AmazonSQSClient.SetQueueAttributes怎么用?C# AmazonSQSClient.SetQueueAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.SQS.AmazonSQSClient的用法示例。


在下文中一共展示了AmazonSQSClient.SetQueueAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SQSSetQueueAttributes

    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
    }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:35,代码来源:SQSSamples.cs

示例2: GrantNotificationPermission

        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);
        }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:31,代码来源:SolutionCode.cs

示例3: MessageDeleted

        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");
            }
        }
开发者ID:Tirael,项目名称:AWSUtilities,代码行数:44,代码来源:SQSServiceTests.cs


注:本文中的Amazon.SQS.AmazonSQSClient.SetQueueAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。