Rollback changes in the @EventHandler method if Exception takes place?


My understanding is that methods annotated with @EventHandler annotation that are also part of the same @ProcessingGroup(“products-group”) are executed within the same Transaction.

I have two @EventHandler methods that are part of the same group and both of these methods write into a database. One method throws an Exception. However, the database changes are not rolled back. I wonder why the database change is not rolled back if both of these event handler methods are executed within the same @ProcessingGroup(“products-group”)? Or is there an additional configuration that I need to make to make for this to work within the same transaction and for changes to be rolled back if one of the @EventHandler methods in the same @ProcessingGroup(“products-group”) throws an Exception?

If you have an article or an example of such configuration may I ask you to share it here with me?

Thank you very much!

I was able to handle an Exception and throw it again. This way it seems to be working well.

  public class ProductsErrorHandler implements ListenerInvocationErrorHandler {
    public void onError(final Exception exception, final EventMessage<?> event, final EventMessageHandler eventHandler) throws Exception {
        throw exception;

Hi Sergey,

that is indeed the way to do it. The default behavior is to log and continue. By declaring a ListenerInvocationErrorHandler you can override that behavior.

Note that you can also use the PropagatingErrorHandler to achieve what you want. It’ll save you one line of code. Not the most complicated line, but still :wink:

Thank you very much, @allardbz :+1: