Reputation: 8254
I am working with Amazon-SQS, I tried to retrieve approximate number of attributes from the queue but the response is null
I am using C# following is the code:
GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);
Console.WriteLine("App. messages: "+ response.ApproximateNumberOfMessages);
I am getting null response from the request, I am sure there are messages in the queue as well.
Upvotes: 5
Views: 4579
Reputation: 26003
You have to explicitly specify which attributes you would like to return from GetQueueAttributes. You didn't specify any, so it didn't return any.
Try simply adding ApproximateNumberOfMessages to the AttributeNames collection on GetQueueAttributesRequest:
GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
attReq.AttributeNames.Add("ApproximateNumberOfMessages");
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);
Notes:
AttributeName
without the last s if you're on an older version of the AWSSDK. It looks like this changed between versions 1.x and 2.x.Upvotes: 11