title: AWS SQS Dead Letter Queue - only in certain cases
body: <p>My question isn't very easy but I believe I will find with Your help the solution for my problem. I have a microservice that reads messages from AWS SQS queue and saves it in Redis.</p>
  
  <p>On AWS I have two queues:</p>
  
  <ol>
  <li>AQueue (standard queue)</li>
  <li>DeadLetterQueue</li>
  </ol>
  
  <p>I'd like to:</p>
  
  <ul>
  <li>Remove messages from my standard queue (AQueue) and move them to DeadLetterQueue when for example there is 5 times error parsing</li>
  <li>When for example my Redis is temporarily unavailable, I'd like to NOT to remove currently read messages. In This case these messages should be read over and over again until the Redis will work.</li>
  </ul>
  
  <p>HOW can I do this? On AWS I have set my standard queue (AQueue) to send messages to  DeadLetterQueue when the messages will fail 5 times</p>
  
  <p>My listener:</p>
  
  <pre><code>@SqsListener(value = "${amazon.sqs.destination}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
      public void receive(String requestJSON, Acknowledgment acknowledgment) {
          try (Jedis jedis = jedisPool.getResource()) {
              if (redisPassword != null &amp;&amp; !redisPassword.isEmpty()) {
                  jedis.auth(redisPassword);
              }
              long key = jedis.incr("Trace:");
              Trace trace = Trace.fromJSON(requestJSON);
              trace.setTechnicalId(Long.toString(key));
              traceRepository.save(trace);
              acknowledgment.acknowledge();
          }catch (IOException e) {
              log.error("Parse error: " + e.getMessage());
              queueMessagingTemplate.convertAndSend(deadLetterQueue, requestJSON);
              acknowledgment.acknowledge();
          } catch(Exception e){
              log.error("Problem with NOSQL database Redis: " + e.getMessage());
          }
  </code></pre>
  
  <p>Unfortunately, EVEN WHEN I don't call <code>acknowledgment.acknowledge();</code> my message after 5 attempts is moving to DeadLetterQueue.</p>