0

I am working on an application where the event causes spring data repository to save data;

Entity entity = entityRepository.save((Entity) event.getPayload());

this code can throw various exceptions, like DataIntegrityViolationException which is runtime exception.

My Question is how to

  • Handle such an exception and
  • generate a Message with Payload caused this error
  • with Exception,
  • allowing Producer to take an action.
Zafar Ali
  • 37
  • 1
  • 8

1 Answers1

0

Add a custom error handler to the binding's listener container...

@Bean
ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> customizer() {
    return (container, dest, group) -> {
        if (group.equals("theOneIWant")) {
            container.setErrorHandler( ... );
        }
    };
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179