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.
This commit is contained in:
@@ -23,7 +23,6 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.aop.support.AbstractPointcutAdvisor;
|
||||
@@ -41,8 +40,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ConcurrentLruCache;
|
||||
|
||||
/**
|
||||
* An {@link Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark the previously registered
|
||||
* event publications as completed on successful method execution.
|
||||
* An {@link org.springframework.aop.Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark
|
||||
* the previously registered event publications as completed on successful method execution.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@@ -177,7 +176,7 @@ public class CompletionRegisteringAdvisor extends AbstractPointcutAdvisor {
|
||||
method, o_O.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
throw o_O;
|
||||
}
|
||||
|
||||
// Mark publication complete if the method is a transactional event listener.
|
||||
|
||||
@@ -192,7 +192,8 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
|
||||
});
|
||||
}
|
||||
|
||||
private void doResubmitUncompletedPublicationsOlderThan(@Nullable Duration duration, Predicate<EventPublication> filter) {
|
||||
private void doResubmitUncompletedPublicationsOlderThan(@Nullable Duration duration,
|
||||
Predicate<EventPublication> filter) {
|
||||
|
||||
var message = duration != null ? "" : " older than %s".formatted(duration);
|
||||
var registry = this.registry.get();
|
||||
@@ -206,8 +207,20 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
|
||||
LOGGER.debug(getConfirmationMessage(publications) + " found.");
|
||||
|
||||
publications.stream() //
|
||||
.filter(filter) //
|
||||
.forEach(this::invokeTargetListener);
|
||||
.filter(filter) //
|
||||
.forEach(it -> {
|
||||
|
||||
try {
|
||||
|
||||
invokeTargetListener(it);
|
||||
|
||||
} catch (Exception o_O) {
|
||||
|
||||
if (LOGGER.isErrorEnabled()) {
|
||||
LOGGER.error("Error republishing event publication " + it, o_O);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ApplicationListener<ApplicationEvent> executeListenerWithCompletion(EventPublication publication,
|
||||
|
||||
Reference in New Issue
Block a user