Skip to content

Commit 0726753

Browse files
committed
Fix ConditionalRejectingErrorHandler for IllegalStateException
Related to: #3396 Now that `DelegatingInvocableHandler` throws an `IllegalStateException` around `NoSuchMethodException`, the logic in the `ConditionalRejectingErrorHandler` for `isFatal()` is not usable anymore. * Change the `ConditionalRejectingErrorHandler.DefaultExceptionStrategy.isFatal()` logic to rely on the `IllegalStateException` instead of `UndeclaredThrowableException` to trigger expected by this error handler `AmqpRejectAndDontRequeueException` recovery
1 parent f734831 commit 0726753

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/ConditionalRejectingErrorHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ public static class DefaultExceptionStrategy implements FatalExceptionStrategy {
202202
@Override
203203
public boolean isFatal(Throwable t) {
204204
Throwable cause = t.getCause();
205-
while ((cause instanceof MessagingException || cause instanceof UndeclaredThrowableException)
205+
while ((cause instanceof MessagingException
206+
|| cause instanceof UndeclaredThrowableException
207+
|| cause instanceof IllegalStateException)
208+
206209
&& !isCauseFatal(cause)) {
207210

208211
cause = cause.getCause();

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import org.springframework.transaction.annotation.EnableTransactionManagement;
142142
import org.springframework.transaction.annotation.Transactional;
143143
import org.springframework.util.ErrorHandler;
144+
import org.springframework.util.ReflectionUtils;
144145
import org.springframework.validation.Errors;
145146
import org.springframework.validation.Validator;
146147
import org.springframework.validation.annotation.Validated;
@@ -2072,6 +2073,14 @@ org.springframework.amqp.core.Queue brokerNamed() {
20722073
return QueueBuilder.nonDurable("").autoDelete().exclusive().build();
20732074
}
20742075

2076+
@Bean
2077+
public SimpleRabbitListenerContainerFactory noSuchMethodListenerContainerFactory() {
2078+
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
2079+
factory.setConnectionFactory(rabbitConnectionFactory());
2080+
factory.setErrorHandler(ReflectionUtils::rethrowRuntimeException);
2081+
return factory;
2082+
}
2083+
20752084
@Bean
20762085
NoSuchMethodService noSuchMethodService() {
20772086
return new NoSuchMethodService();
@@ -2509,7 +2518,8 @@ public String projection(Sample in) {
25092518
}
25102519
}
25112520

2512-
@RabbitListener(id = "no.such.method", queues = "no.such.method")
2521+
@RabbitListener(id = "no.such.method", queues = "no.such.method",
2522+
containerFactory = "noSuchMethodListenerContainerFactory")
25132523
static class NoSuchMethodService implements ApplicationListener<ListenerContainerConsumerFailedEvent> {
25142524

25152525
CountDownLatch eventLatch = new CountDownLatch(1);

0 commit comments

Comments
 (0)