Skip to content

Commit b4bb541

Browse files
committed
GH-372 - Propagate original exception from CompletionRegisteringAdvisor.
We now propagate potentially occurring exceptions in CompletionRegisteringAdvisor to make sure the standard exception handling facilities kick in, both for synchronous and asynchronous listener invocations. This implies that during republication we need to handle exceptions to make sure that failing synchronous listeners to not prevent the submission of subsequent publications. We currently log such exceptions into error.
1 parent 9d30fcd commit b4bb541

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/CompletionRegisteringAdvisor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.aopalliance.intercept.MethodInvocation;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26-
import org.springframework.aop.Advisor;
2726
import org.springframework.aop.MethodMatcher;
2827
import org.springframework.aop.Pointcut;
2928
import org.springframework.aop.support.AbstractPointcutAdvisor;
@@ -41,8 +40,8 @@
4140
import org.springframework.util.ConcurrentLruCache;
4241

4342
/**
44-
* An {@link Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark the previously registered
45-
* event publications as completed on successful method execution.
43+
* An {@link org.springframework.aop.Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark
44+
* the previously registered event publications as completed on successful method execution.
4645
*
4746
* @author Oliver Drotbohm
4847
*/
@@ -177,7 +176,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
177176
method, o_O.getMessage());
178177
}
179178

180-
return result;
179+
throw o_O;
181180
}
182181

183182
// Mark publication complete if the method is a transactional event listener.

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ private void invokeTargetListener(TargetEventPublication publication) {
192192
});
193193
}
194194

195-
private void doResubmitUncompletedPublicationsOlderThan(@Nullable Duration duration, Predicate<EventPublication> filter) {
195+
private void doResubmitUncompletedPublicationsOlderThan(@Nullable Duration duration,
196+
Predicate<EventPublication> filter) {
196197

197198
var message = duration != null ? "" : " older than %s".formatted(duration);
198199
var registry = this.registry.get();
@@ -206,8 +207,20 @@ private void doResubmitUncompletedPublicationsOlderThan(@Nullable Duration durat
206207
LOGGER.debug(getConfirmationMessage(publications) + " found.");
207208

208209
publications.stream() //
209-
.filter(filter) //
210-
.forEach(this::invokeTargetListener);
210+
.filter(filter) //
211+
.forEach(it -> {
212+
213+
try {
214+
215+
invokeTargetListener(it);
216+
217+
} catch (Exception o_O) {
218+
219+
if (LOGGER.isErrorEnabled()) {
220+
LOGGER.error("Error republishing event publication " + it, o_O);
221+
}
222+
}
223+
});
211224
}
212225

213226
private static ApplicationListener<ApplicationEvent> executeListenerWithCompletion(EventPublication publication,

0 commit comments

Comments
 (0)