spring-projects / spring-modulith

Modular applications with Spring Boot
https://spring.io/projects/spring-modulith
Apache License 2.0
758 stars 119 forks source link

Marker interfaces for domain events #651

Open cmetzlerhg opened 2 months ago

cmetzlerhg commented 2 months ago

Hi,

we're currently integrating the transactional outbox with spring-data-jpa and spring-modulith. In our current code, we have use cases where we use

// We're not using @Async here, because the executed code is already creating a new thread
@TransactionalEventListener(SomethingHappenedEvent.class)
void handleSomeEvent() {
  //  react on something has happened without the need for its actual content 
}

It seems that @ApplicationModuleListener does not support specifying the class of the event and if we use the @TransactionalEventListener as before, we run into an IndexOutOfBounds exception, when trying to replay failed events.

Our workaround is now to add the parameter to the method signature, however it is not used, so the static code analysis shows an unused parameter.

odrotbohm commented 2 months ago

Do you have a stack trace for the exception handy? From a quick glance, I cannot find any code in Spring Modulith that strongly expects method parameter being present.

cmetzlerhg commented 2 months ago

Unfortunately not at the moment, I will try to roll back to a state, where we had the issue and see if I can reproduce it.

odrotbohm commented 2 months ago

Nevermind, I got it: CompletionRegisteringMethod.invoke(…).

odrotbohm commented 2 months ago

I'm afraid we cannot do anything about this for now, as the database interaction for the event completion needs access to the original event, and we only operate in the context of the method invocation. If you do not declare the parameter, the event will not be handed into the invocation, and we cannot distinguish which of potentially multiple registered event publications to mark completed.