Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 753
Wim Deblauwe Avatar asked Jan 01 '26 06:01

Wim Deblauwe


1 Answers

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.

like image 138
Emanuel Trandafir Avatar answered Jan 04 '26 13:01

Emanuel Trandafir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!