spring-modulith icon indicating copy to clipboard operation
spring-modulith copied to clipboard

Thoughts on making the `PersistentApplicationEventMulticaster.invokeTargetListener` method public

Open JakeTiritilli opened this issue 1 year ago • 4 comments
trafficstars

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.

JakeTiritilli avatar Apr 12 '24 15:04 JakeTiritilli

Interested in this as well.

I think invokeTargetListener may make sense to be exposed as part of IncompleteEventPublications interface. Maybe resubmitIncompletePublication(TargetEventPublication)?

pcuriel avatar Apr 15 '24 18:04 pcuriel

Can you elaborate how you'd get hold of individual TargetEventPublications? Via the EventPublicationRegistry I assume?

odrotbohm avatar Apr 16 '24 06:04 odrotbohm

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);
}

JakeTiritilli avatar Apr 16 '24 14:04 JakeTiritilli

@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.

JakeTiritilli avatar Jun 11 '24 23:06 JakeTiritilli