spring amqp enable retry by configuration and prevent it according to a specified exception
<p>I have the following two cases</p>

<ol>
<li>In case of <strong>ExceptionA</strong> :  retrying for finite number of times
and finally when number of retrials exhausted, message is written in
a dead letter queue</li>
<li>In case of <strong>ExceptionB</strong> : simply, message should be written to
dead letter queue</li>
</ol>

<p>I want to support the two cases on the same listener container factory and the same queue.</p>

<p>I already have the following configuration to support <strong>case 1</strong> successfully:</p>

<pre><code>@Bean
public RetryOperationsInterceptor workMessagesRetryInterceptor() {
        return RetryInterceptorBuilder.stateless()
                .maxAttempts(5)
                .backOffOptions(1000, 2, 10000)
                .recoverer(new RejectAndDontRequeueRecoverer())
                .build();
    }




@Bean
public SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory);
  factory.setMaxConcurrentConsumers(8);
  factory.setAdviceChain(workMessagesRetryInterceptor());


  return factory;
}`
</code></pre>

<p>Now I want to extend the previous configuration to support case 2 too.</p>

<hr>

<p>Edit, thanks Gary for your fast response.</p>

<p>Here you are my new configuration, but I still <strong>get retrials</strong> on both the two exceptions : ListenerExecutionFailedException , AmqpRejectAndDontRequeueException</p>

<pre><code>@Bean
    public SimpleRetryPolicy rejectionRetryPolicy(){

        Map&lt;Class&lt;? extends Throwable&gt; , Boolean&gt; exceptionsMap = new HashMap&lt;Class&lt;? extends Throwable&gt; , Boolean&gt;();
        exceptionsMap.put(ListenerExecutionFailedException.class, true); //retriable
        exceptionsMap.put(AmqpRejectAndDontRequeueException.class, false);//not retriable


        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(5 , exceptionsMap );




        return retryPolicy;
    }

    @Bean
    public RetryOperationsInterceptor workMessagesRetryInterceptor() {
        return RetryInterceptorBuilder.stateless().retryPolicy(rejectionRetryPolicy())

                //.backOffOptions(1000, 2, 10000)
                //.recoverer(new RejectAndDontRequeueRecoverer())
                .build();
    }
</code></pre>