Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I have queue name is testqueue in Amazon SQS. Testqueue contain 100-500 message. I got 10 message from the testqueue using below given code but i want to get all message which is available in testqueue.
 public class Program
    {
        public static void Main(string[] args)
        {
            AmazonSQSClient objClient = new AmazonSQSClient
            ("A************", "************t***********", Amazon.RegionEndpoint.USWest2);

            //Confirming the queue exists
            ListQueuesRequest listQueuesRequest = new ListQueuesRequest();
            ListQueuesResponse listQueuesResponse = objClient.ListQueues(listQueuesRequest);

            Console.WriteLine("Printing list of Amazon SQS queues.\n");
            foreach (String queueUrl in listQueuesResponse.QueueUrls)
            {
                Console.WriteLine("  QueueUrl: {0}", queueUrl);

                //Receiving a message
                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.QueueUrl = queueUrl;
                receiveMessageRequest.MaxNumberOfMessages = 10;

                ReceiveMessageResponse receiveMessageResponse = objClient.ReceiveMessage(receiveMessageRequest);
             
                Console.WriteLine("Printing received message.\n");
                foreach (Message message in receiveMessageResponse.Messages)
                {
                    Console.WriteLine("Message");
                    Console.WriteLine("MessageId: {0}", message.MessageId);
                    Console.WriteLine("ReceiptHandle: {0}", message.ReceiptHandle);
                    Console.WriteLine("MD5OfBody: {0}", message.MD5OfBody);
                    Console.WriteLine("Body: {0}", message.Body);

                    foreach (KeyValuePair<string, string> entry in message.Attributes)
                    {
                        Console.WriteLine("Attribute");
                        Console.WriteLine("Name: {0}", entry.Key);
                        Console.WriteLine("Value: {0}", entry.Value);
                    }
                }
                String messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;
            }
            Console.WriteLine();

            Console.WriteLine("Read the queue");
            
            Console.ReadLine();
        }
    }

Thanks,
The Rock


What I have tried:

Above given code return only 10 message out 0f 1000 message. but i want 1000 message. Can some one help me to get rid of this situation.

Thanks
Happy coding
Posted
Updated 16-May-16 9:27am
v2
Comments
Yashebay 15-May-16 8:25am    
Read all message of queue(Here name is testqueue) in the AmazonSqs, Can someone guide me

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

From your code, a foreach may not be the right way to get all messages. Or the list is not filled correctly.
[Update]
Is it possible that the root of your problem is this line ?
Quote:
C#
receiveMessageRequest.MaxNumberOfMessages = 10;
 
Share this answer
 
v2
Comments
Patrice T 15-May-16 11:20am    
I have never used Amazon SQS. But I know what can be done with a debugger. With the debugger you must be able to narrow the research to a few lines of code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900