title: Handling validation error of a JSON payload in Spring RabbitListener
body: <p>Let's take the following consumer method for a RabbitMQ queue. Ths payload received from the queue is in JSON format, so I register a bean returning a <code>Jackson2JsonMessageConverter</code>. This basically works fine.</p>
  <p>Now I'd like to add a validation of the <code>QueueResponse</code> object, similar to when using Jackson in a <code>@RestController</code>, e.g. if the JSON field does not exist or contains an invalid value. In this case, I'd like the code to execute the <code>catch</code> block, i.e. throwing an <code>AmqpRejectAndDontRequeueException</code>.</p>
  <p>Thus, I added <code>@Payload @Valid</code> as described <a href="https://docs.spring.io/spring-amqp/docs/current/reference/html/#rabbit-validation" rel="nofollow noreferrer">in the documentation</a>. But I don't know what to do in the <code>validationErrorHandler</code> method. I don't understand the return statement from the documentation. What would I need to do there to reach the <code>catch</code> block?</p>
  <pre class="lang-java prettyprint-override"><code>@RabbitListener(queues = QUEUE_NAME, messageConverter = &quot;jackson2MessageConverter&quot;, errorHandler=&quot;validationErrorHandler&quot;)
  public void consume(@Payload @Valid QueueResponse queueResponse) {
      try {
          processMessage(queueResponse);
      } catch (Exception e) {
          throw new AmqpRejectAndDontRequeueException(e.getMessage());
      }
  }
  
  @Bean
  public MessageConverter jackson2MessageConverter() {
      return new Jackson2JsonMessageConverter(objectMapper);
  }
  
  // Not sure what to do here...
  @Bean
  public RabbitListenerErrorHandler validationErrorHandler() {
      return (m, e) -&gt; {
          ...
      };
  }
  </code></pre>