spring-bootspring-modulith

How to configure retries for failed Spring application events persisted with Spring Modulith's Event Publication Repository?


I am investigating how the Event Publication Repository in Spring Modulith works. I have it working so that when a listener fails, the event is stored in the registry as incomplete. According to the documentation, the event should be re-delivered to my listener when I restart the application, but this is not happening.

Moreover, I would like to have it retry while the application is running as well to use it as a Transactional Outbox pattern. How should I configure this?

You can view my test project at transactional-outbox-spring-modulith.

EDIT: It seems the redelivery at startup is not by default, you need to set spring.modulith.republish-outstanding-events-on-restart=true in application.properties, then it works fine. However, my question on how to have retries while the application runs still holds.


Solution

  • As an alternative to the republish-outstanding-events-on-restart property, there are two Spring beans you can use to interact with the events.

    IncompleteEventPublications incompleteEvents;
    CompletedEventPublications completeEvents;
    

    They offer minimal API that allows you to fetch or re-submit incomplete events, and fetch or delete the completed ones, based on some time ranges (see example).

    Lastly, if you want, you can query the database directly (select * from event_publication), but I'm not sure how this will be better than the previous solution.