title: Why is the value of "rabbitmq_rejected_total" wrong?
body: <p>I have a Spring Boot application with Spring AMQP. I don't want to redeliver failed messages endlessly, so I configured error handling with <code>max-attempts</code> to 10, see <a href="https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#appendix.application-properties.integration" rel="nofollow noreferrer">.A.8. Integration Properties</a>:</p>
  <blockquote>
  <p><code>spring.rabbitmq.listener.simple.retry.enabled</code> - Whether publishing retries are enabled.<br />
  [...]<br />
  <code>spring.rabbitmq.listener.simple.retry.max-attempts</code>- Maximum number of attempts to deliver a message.</p>
  </blockquote>
  <p>This configuration stops redelivering failed messages endlessly, but if I call <code>/prometheus</code> I only get the value 1. Why is the value 1 instead of 10?</p>
  <p><strong>Code</strong></p>
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  public class TestApplication {
    public static void main(String[] args) {
      SpringApplication.run(TestApplication.class, args);
    }
  
    @RabbitListener(queues = &quot;q_test&quot;)
    public void listen(@Payload final String text) {
      throw new RuntimeException(&quot;test&quot;);
    }
  }
  </code></pre>
  <p><strong>Configuration</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>spring:
    rabbitmq:
      host: localhost 
      port: 5672      
      username: guest 
      password: guest
      listener:
        simple:
          retry:
            enabled: true
            max-attempts: 10 
  </code></pre>
  <p><strong>Logs</strong></p>
  <pre><code>2022-03-24 20:02:04.497  WARN 9740 --- [ntContainer#0-1] o.s.a.r.r.RejectAndDontRequeueRecoverer  : Retries exhausted for message (Body:'[B@46578db6(byte[21])' MessageProperties [headers={}, contentLength=0, receivedDeliveryMode=NON_PERSISTENT, redelivered=false, receivedExchange=, receivedRoutingKey=q_test, deliveryTag=1, consumerTag=amq.ctag-JlV1RlVT3dfQVvQuC_1Otw, consumerQueue=q_test])
  
  org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener method 'public void test.TestApplication.listen(java.lang.String)' threw exception
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:270) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:207) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:146) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1665) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1584) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
      at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.16.jar:5.3.16]
      at io.opentracing.contrib.spring.rabbitmq.RabbitMqReceiveTracingInterceptor.invoke(RabbitMqReceiveTracingInterceptor.java:48) ~[opentracing-spring-rabbitmq-3.0.0.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:93) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:116) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.amqp.rabbit.listener.$Proxy116.invokeListener(Unknown Source) ~[na:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:967) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:914) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1291) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1197) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
  Caused by: java.lang.RuntimeException: test
      at test.TestApplication.listen(TestApplication.java:22) ~[classes/:na]
      [...]
  
  2022-03-24 20:02:04.498  WARN 9740 --- [ntContainer#0-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
  
  org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Retry Policy Exhausted
      at org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer.recover(RejectAndDontRequeueRecoverer.java:76) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean.lambda$createRecoverer$0(StatelessRetryOperationsInterceptorFactoryBean.java:74) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:142) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:539) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:387) ~[spring-retry-1.3.1.jar:na]
  at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:116) ~[spring-retry-1.3.1.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.16.jar:5.3.16]
      at org.springframework.amqp.rabbit.listener.$Proxy116.invokeListener(Unknown Source) ~[na:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:967) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:914) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1291) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1197) ~[spring-rabbit-2.4.2.jar:2.4.2]
      at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
  Caused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: null
      [...]
  </code></pre>
  <p><strong>Metrics</strong></p>
  <pre><code># HELP rabbitmq_rejected_total  
  # TYPE rabbitmq_rejected_total counter
  rabbitmq_rejected_total{application=&quot;test&quot;,name=&quot;rabbit&quot;,} 1.0
  </code></pre>
  <p><strong>Research</strong></p>
  <p>Without the Spring Boot configuration, the value of <code>rabbitmq_rejected_total</code> is growing endlessly.</p>