title: AWS SQS Java. Not all messages are retrieved from the SQS queue
body: <p>I have been trying several approaches to retrieve all messages from the SQS queue by using AWS SDK for Java to no avail. I have read about the distributed nature of the AWS SQS and that messages are stored on the different servers. But what I do not understand is why this architecture is not hidden from the end user. What tricks do I have to apply in Java code to retrieve all messages and be 100% sure that no one was missed?</p>
  
  <p><strong>I tried this with the "Long Polling"</strong>:</p>
  
  <pre><code>ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
  List&lt;Message&gt; messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
  for (Message message : messages) {
  System.out.println(" Message");
  System.out.println(" MessageId: " + message.getMessageId());
  System.out.println(" ReceiptHandle: " + message.getReceiptHandle());
  System.out.println(" MD5OfBody: " + message.getMD5OfBody());
  System.out.println(" Body: " + message.getBody());
  for (Entry&lt;String, String&gt; entry : message.getAttributes().entrySet()) {
  System.out.println(" Attribute");
  System.out.println(" Name: " + entry.getKey());
  System.out.println(" Value: " + entry.getValue());
  }
  }
  System.out.println();
  </code></pre>
  
  <p><strong>And this with Request Batching / Client-Side Buffering:</strong></p>
  
  <pre><code>    // Create the basic Amazon SQS async client
      AmazonSQSAsync sqsAsync = new AmazonSQSAsyncClient();
  
      // Create the buffered client
      AmazonSQSAsync bufferedSqs = new AmazonSQSBufferedAsyncClient(sqsAsync);
  
      CreateQueueRequest createRequest = new CreateQueueRequest().withQueueName("MyTestQueue");
  
      CreateQueueResult res = bufferedSqs.createQueue(createRequest);
  
      SendMessageRequest request = new SendMessageRequest();
      String body = "test message_" + System.currentTimeMillis();
      request.setMessageBody( body );
      request.setQueueUrl(res.getQueueUrl());
  
      SendMessageResult sendResult = bufferedSqs.sendMessage(request);
  
      ReceiveMessageRequest receiveRq = new ReceiveMessageRequest()
      .withMaxNumberOfMessages(10)
      .withQueueUrl(queueUrl);
      ReceiveMessageResult rx = bufferedSqs.receiveMessage(receiveRq);
  
      List&lt;Message&gt; messages = rx.getMessages();
      for (Message message : messages) {
      System.out.println(" Message");
      System.out.println(" MessageId: " + message.getMessageId());
      System.out.println(" ReceiptHandle: " + message.getReceiptHandle());
      System.out.println(" MD5OfBody: " + message.getMD5OfBody());
      System.out.println(" Body: " + message.getBody());
      for (Entry&lt;String, String&gt; entry : message.getAttributes().entrySet()) {
      System.out.println(" Attribute");
      System.out.println(" Name: " + entry.getKey());
      System.out.println(" Value: " + entry.getValue());
      }
      }
  </code></pre>
  
  <p>But I am still unable to retrieve all messages.</p>
  
  <p>Any idea?</p>
  
  <p>AWS Forum keeps silence on my post.</p>