spring-modulith
spring-modulith copied to clipboard
Thoughts on making the `PersistentApplicationEventMulticaster.invokeTargetListener` method public
Hi, I was wondering if it would be possible to make the PersistentApplicationEventMulticaster.invokeTargetListener(TargetEventPublication) method or some version of it public so that it can be invoked directly.
We have a use case where we built a couple child tables that are associated with the event_publication table to keep track of the number of times an event has been retried. Because of this, we've written our own query to find the list of event publications that need to be resubmitted and would like to be able to invoke the target listener for each one without having a second query be executed. The resubmitIncompletePublications method works, but it's running the findIncompletePublications query each time it's invoked, which is a fairly costly operation given that we already have all of the required data in memory.
Interested in this as well.
I think invokeTargetListener may make sense to be exposed as part of IncompleteEventPublications interface. Maybe resubmitIncompletePublication(TargetEventPublication)?
Can you elaborate how you'd get hold of individual TargetEventPublications? Via the EventPublicationRegistry I assume?
For our use case, we wrote our own EventPublication entity so that associations with child tables that we built could be added. I wanted to be able to retrieve all of the results with one JPQL query that does a join. This is a bit of an oversimplification, but the code would look something like this:
var retryableEventPublications = eventPublicationRepo.findRetryableEventPublications();
for (var eventPublication : retryableEventPublications) {
var targetEventPublication = TargetEventPublication.of(
deserializeEvent(eventPublication.getSerializedEvent(), eventPublication.getEventType()),
PublicationTargetIdentifier.of(eventPublication.getListenerId()),
eventPublication.getPublicationDate());
applicationEventMulticaster.invokeTargetListener(targetEventPublication);
}
@odrotbohm I just wanted to follow up with this to see if that's something you'd want to allow. I'd be willing to contribute the change if we can align on the approach.