GetQueueAttributes() public method

Gets attributes for the specified queue.

Some actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers starting from 1. For example, a parameter list with two elements looks like this:

&Attribute.1=this

&Attribute.2=that

/// The attribute referred to doesn't exist. ///
public GetQueueAttributes ( GetQueueAttributesRequest request ) : GetQueueAttributesResponse
request Amazon.SQS.Model.GetQueueAttributesRequest Container for the necessary parameters to execute the GetQueueAttributes service method.
return Amazon.SQS.Model.GetQueueAttributesResponse
        public virtual string GetQueueArn(AmazonSQSClient sqsClient, string queueUrl)
        {
            string queueArn;
            // Construct a GetQueueAttributesRequest for the URL to retrieve the ARN
            var getQueueAttributesRequest = new GetQueueAttributesRequest
            {
                QueueUrl = queueUrl,
                AttributeNames =
                {
                    "QueueArn"
                }
            };

            // Submit the request
            GetQueueAttributesResponse getQueueAttributesResponse =
                sqsClient.GetQueueAttributes(getQueueAttributesRequest);

            // Add the discovered ARN to the queueArnList variable.
            queueArn = getQueueAttributesResponse.QueueARN;
            return queueArn;
        }
Esempio n. 2
0
        /// <summary>
        /// Callback for windowing the SQS messages ordered by time queued
        /// </summary>
        /// <param name="state"></param>
        private void WindowCallback(Object state)
        {
            try
            {
                CancellationToken ct = (CancellationToken)state;
                List<Message> messages = new List<Message>();

                // syncronize the processing of windows
                if ((!ct.IsCancellationRequested) &
                    (Monitor.TryEnter(_windowLock, 1000)))
                {
                    try
                    {
                        long epochWindowTime = ToEpochTimeInMilliseconds(DateTime.UtcNow.Subtract(this.SQSWindow));
                        int numberOfMessages = 0;

                        // 1st query to determine the # of Messages available in the queue
                        using (AmazonSQSClient client = new AmazonSQSClient(
                            this.AWSAccessKey, this.AWSSecretAccessKey,
                            new AmazonSQSConfig() { ServiceURL = this.AWSSQSServiceUrl }))
                        {
                            // get the NumberOfMessages to optimize how to Receive all of the messages from the queue
                            GetQueueAttributesRequest attributesRequest = new GetQueueAttributesRequest();
                            attributesRequest.QueueUrl = this.QueueUrl;
                            attributesRequest.AttributeName.Add("ApproximateNumberOfMessages");
                            numberOfMessages = client.GetQueueAttributes(attributesRequest).GetQueueAttributesResult.ApproximateNumberOfMessages;
                        }

                        // determine if we need to Receive messages from the Queue
                        if (numberOfMessages > 0)
                        {
                            if (numberOfMessages < 10)
                            {
                                // just do it inline it's less expensive than spinning threads
                                ReceiveTask(ct, numberOfMessages);
                            }
                            else
                            {
                                // use the default partitioner to determine the number of tasks
                                // TODO Create a custom partitioner that takes into account the batch x 10 of SQS
                                Parallel.ForEach(Partitioner.Create(0, numberOfMessages),
                                    (range) => ReceiveTask(ct, range.Item2 - range.Item1));
                            }
                        }

                        // ok so all messages have been Receieved and ordered or no more messages can be popped
                        if (!ct.IsCancellationRequested)
                        {
                            // get all messages less than the window time from the rb tree
                            // probably don't have to lock on _setLock because of the _windowLock but let's be safe
                            lock (_setLock)
                            {
                                messages.AddRange(_set.Where((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime));
                                _set.RemoveWhere((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime);
                            }

                            // remove duplicates
                            //TODO Find a better way to dedup that doesn't destroy the order of the array
                            IEnumerable<Message> dedupMessages = messages.Distinct(new MessageEqualityComparer());

                            // distinct doesn't presever order so we need to reorder the window
                            IEnumerable<Message> orderedMessages = dedupMessages.OrderBy(m => m, new MessageSentTimeStampComparer());

                            // raise the WindowEvent with the results
                            if (!ct.IsCancellationRequested)
                            {
                                OnNewWindow(dedupMessages);
                            }
                        }

                    }
                    finally
                    {
                        Monitor.Exit(_windowLock);
                    }
                }

                // check if we should delete the messages
                if ((!ct.IsCancellationRequested) &
                    (messages.Count > 0))
                {
                    if (messages.Count < 10)
                    {
                        DeleteTask(ct, messages, new Tuple<int, int>(0, messages.Count));
                    }
                    else
                    {
                        // use the default partitioner to determine the number of tasks
                        // TODO Create a custom partitioner that takes into account the batch x 10 of SQS
                        Parallel.ForEach(Partitioner.Create(0, messages.Count),
                            (range) => DeleteTask(ct, messages, range));
                    }
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(this.GetType().Name,
                    ex.Message + "\n" + ex.StackTrace,
                    EventLogEntryType.Error);
            }
        }
Esempio n. 3
0
        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");
            }
        }
Esempio n. 4
0
    public static void SQSGetQueueAttributes()
    {
      #region SQSGetQueueAttributes
      var client = new AmazonSQSClient();

      var request = new GetQueueAttributesRequest
      {
        QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue",
        AttributeNames = new List<string>() { "All" }
      };

      var response = client.GetQueueAttributes(request);

      Console.WriteLine("Attributes for queue ARN '" + response.QueueARN + "':");
      Console.WriteLine("  Approximate number of messages:" +
        response.ApproximateNumberOfMessages);
      Console.WriteLine("  Approximate number of messages delayed: " +
        response.ApproximateNumberOfMessagesDelayed);
      Console.WriteLine("  Approximate number of messages not visible: " +
        response.ApproximateNumberOfMessagesNotVisible);
      Console.WriteLine("  Queue created on: " + response.CreatedTimestamp);
      Console.WriteLine("  Delay seconds: " + response.DelaySeconds);
      Console.WriteLine("  Queue last modified on: " +
        response.LastModifiedTimestamp);
      Console.WriteLine("  Maximum message size: " +
        response.MaximumMessageSize);
      Console.WriteLine("  Message retention period: " +
        response.MessageRetentionPeriod);
      Console.WriteLine("  Visibility timeout: " + response.VisibilityTimeout);
      Console.WriteLine("  Policy: " + response.Policy);
      Console.WriteLine("  Attributes:");

      foreach (var attr in response.Attributes)
      {
        Console.WriteLine("    " + attr.Key + ": " + attr.Value);
      }
      #endregion

      Console.ReadLine();
    }
Esempio n. 5
0
        public static int QueueLengthByQueueUrl(string queueUrl)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new GetQueueAttributesRequest
                {
                    QueueUrl = queueUrl,
                    AttributeNames = new List<string> { "ApproximateNumberOfMessages" }
                };

                return client.GetQueueAttributes(request).ApproximateNumberOfMessages;
            }
        }