private GetQueueAttributesResult GetTaskQueueAttr(Priority oPriority) { string strUrlQueue = GetQueueUrl(oPriority); GetQueueAttributesResult oGetQueueAttributesResult = null; try { using (AmazonSQS oSQSClient = AWSClientFactory.CreateAmazonSQSClient()) { GetQueueAttributesRequest oGetQueueAttributesRequest = new GetQueueAttributesRequest(); oGetQueueAttributesRequest.QueueUrl = strUrlQueue; GetQueueAttributesResponse oGetQueueAttributesResponse = oSQSClient.GetQueueAttributes(oGetQueueAttributesRequest); if (oGetQueueAttributesResponse.IsSetGetQueueAttributesResult()) { oGetQueueAttributesResult = oGetQueueAttributesResponse.GetQueueAttributesResult; } } } catch (AmazonSQSException) { } catch { } return(oGetQueueAttributesResult); }
private void SetOutputProperties(GetQueueAttributesResult attributes) { ApproximateNumberOfMessages = GetAttributeValue(attributes, "ApproximateNumberOfMessages"); ApproximateNumberOfMessagesNotVisible = GetAttributeValue(attributes, "ApproximateNumberOfMessagesNotVisible"); VisibilityTimeout = GetAttributeValue(attributes, "VisibilityTimeout"); CreatedTimestamp = GetAttributeValue(attributes, "CreatedTimestamp"); LastModifiedTimestamp = GetAttributeValue(attributes, "LastModifiedTimestamp"); //Policy is not a string. //Policy = GetAttributeValue(attributes, "Policy"); MaximumMessageSize = GetAttributeValue(attributes, "MaximumMessageSize"); MessageRetentionPeriod = GetAttributeValue(attributes, "MessageRetentionPeriod"); QueueArn = GetAttributeValue(attributes, "QueueArn"); }
private static int GetTotalMessages(SqsMessage pQueue) { AmazonSQSClient sqs = SqsConfig.Initialize; GetQueueAttributesRequest queueAttributesRequest = new GetQueueAttributesRequest(pQueue.QueueUrl, new List <string> { "All" }); GetQueueAttributesResult queueAttributesResult = sqs.GetQueueAttributes(queueAttributesRequest); if (queueAttributesResult.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new ApplicationException("Problems in the endpoint communication!"); } return(queueAttributesResult.ApproximateNumberOfMessages); }
public static int Count(string queue_url) { AmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient(); GetQueueAttributesRequest gqreq = new GetQueueAttributesRequest(); gqreq.QueueUrl = queue_url; List <string> attr = new List <string>(); attr.Add("All"); gqreq.AttributeName = attr; GetQueueAttributesResponse gqres = sqs.GetQueueAttributes(gqreq); GetQueueAttributesResult gqrst = gqres.GetQueueAttributesResult; //Console.WriteLine("Invisible Messages:" + gqrst.ApproximateNumberOfMessagesNotVisible.ToString()); //Console.WriteLine("Messages:" + gqrst.ApproximateNumberOfMessages); return(gqrst.ApproximateNumberOfMessages); }
protected override bool Execute(AmazonSQS client) { Logger.LogMessage(MessageImportance.Normal, "Getting SQS Queue attributes for queue at {0}", QueueUrl); GetQueueAttributesResult attributes = GetQueueAttributes(client, QueueUrl); if (attributes.IsSetAttribute()) { SetOutputProperties(attributes); Logger.LogMessage(MessageImportance.Low, "Got SQS attributes for Queue {0}", QueueUrl); return(true); } Logger.LogMessage(MessageImportance.High, "Failed to get SQS attributes for Queue {0}", QueueUrl); return(false); }
public void Test_GetQueueAttributes_And_Check_For_Valid_Value() { bool hasCallbackArrived = false; string actualValue = "-1"; string expectedValue = "3"; SQSResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; GetQueueAttributesResponse response = result as GetQueueAttributesResponse; if (null != response) { GetQueueAttributesResult attributeResult = response.GetQueueAttributesResult; if (null != attributeResult) { if (response.GetQueueAttributesResult.Attribute.Count > 0) { actualValue = response.GetQueueAttributesResult.Attribute[0].Value; } } } hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; //Create request object. GetQueueAttributesRequest request = new GetQueueAttributesRequest(); request.QueueUrl = string.Format("{0}/{1}", QueueURL, _queue_UnitTesting); request.AttributeName.Add("VisibilityTimeout"); _client.GetQueueAttributes(request); EnqueueConditional(() => hasCallbackArrived); EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue)); EnqueueTestComplete(); }
private string GetAttributeValue(GetQueueAttributesResult attributeResults, string attributeName) { return(attributeResults.Attribute.Where(x => x.Name == attributeName).FirstOrDefault().Value); }