AMQP-334 Support Unwrapping Exceptions for Retry

With Spring AMQP, the exception thrown to the
RetryTemplate is a ListenerExecutionFailedException
with the business exception in the cause. This means
Exception categorization does not work.

Provide a retry policy/classifier that can examine
exception causes until a match is found.

If so configured, the retry policy should categorize
exceptions by traversing the cause if the current
exception is not itself categorized.
This commit is contained in:
Gary Russell
2013-09-27 17:36:41 -04:00
parent d9ee15606e
commit 6396f11878
5 changed files with 123 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,6 +56,15 @@ public class BinaryExceptionClassifierTests {
assertTrue(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo")));
}
@Test
public void testClassifyExactMatchInCause() {
Collection<Class<? extends Throwable>> set = Collections
.<Class<? extends Throwable>> singleton(IllegalStateException.class);
BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(set);
binaryExceptionClassifier.setTraverseCauses(true);
assertTrue(binaryExceptionClassifier.classify(new RuntimeException(new IllegalStateException("Foo"))));
}
@Test
public void testTypesProvidedInConstructor() {
classifier = new BinaryExceptionClassifier(Collections
@@ -69,4 +78,12 @@ public class BinaryExceptionClassifierTests {
.<Class<? extends Throwable>> singleton(IllegalStateException.class), false);
assertFalse(classifier.classify(new IllegalStateException("Foo")));
}
@Test
public void testTypesProvidedInConstructorWithNonDefaultInCause() {
classifier = new BinaryExceptionClassifier(Collections
.<Class<? extends Throwable>> singleton(IllegalStateException.class), false);
classifier.setTraverseCauses(true);
assertFalse(classifier.classify(new RuntimeException(new RuntimeException(new IllegalStateException("Foo")))));
}
}