Skip to content

Commit 2d22b24

Browse files
committed
GH-381 - 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.
1 parent 1acd2fd commit 2d22b24

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.context.ApplicationListener;
3030
import org.springframework.context.PayloadApplicationEvent;
3131
import org.springframework.context.event.AbstractApplicationEventMulticaster;
32-
import org.springframework.context.event.ApplicationEventMulticaster;
3332
import org.springframework.context.event.ApplicationListenerMethodAdapter;
3433
import org.springframework.core.ResolvableType;
3534
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
@@ -41,14 +40,13 @@
4140
import org.springframework.modulith.events.core.PublicationTargetIdentifier;
4241
import org.springframework.transaction.event.TransactionPhase;
4342
import org.springframework.transaction.event.TransactionalApplicationListener;
44-
import org.springframework.transaction.event.TransactionalEventListener;
4543
import org.springframework.util.Assert;
4644
import org.springframework.util.ReflectionUtils;
4745

4846
/**
49-
* An {@link ApplicationEventMulticaster} to register {@link EventPublication}s in an {@link EventPublicationRegistry}
50-
* so that potentially failing transactional event listeners can get re-invoked upon application restart or via a
51-
* schedule.
47+
* An {@link org.springframework.context.event.ApplicationEventMulticaster} to register {@link EventPublication}s in an
48+
* {@link EventPublicationRegistry} so that potentially failing transactional event listeners can get re-invoked upon
49+
* application restart or via a schedule.
5250
* <p>
5351
* Republication is handled in {@link #afterSingletonsInstantiated()} inspecting the {@link EventPublicationRegistry}
5452
* for incomplete publications and
@@ -174,7 +172,13 @@ private void invokeTargetListener(EventPublication publication) {
174172
private ApplicationListener<ApplicationEvent> executeListenerWithCompletion(EventPublication publication,
175173
TransactionalApplicationListener<ApplicationEvent> listener) {
176174

177-
listener.processEvent(publication.getApplicationEvent());
175+
try {
176+
listener.processEvent(publication.getApplicationEvent());
177+
} catch (Exception o_O) {
178+
if (LOGGER.isErrorEnabled()) {
179+
LOGGER.error("Error republishing event publication " + publication, o_O);
180+
}
181+
}
178182

179183
return listener;
180184
}
@@ -212,7 +216,7 @@ private static boolean matches(ApplicationEvent event, Object payload, Applicati
212216
* implement {@link TransactionalApplicationListener}.
213217
*
214218
* @author Oliver Drotbohm
215-
* @see TransactionalEventListener
219+
* @see org.springframework.transaction.event.TransactionalEventListener
216220
* @see TransactionalApplicationListener
217221
*/
218222
static class TransactionalEventListeners {

0 commit comments

Comments
 (0)