Closed juliofalbo closed 5 years ago
How about?
@EnableRabbitRetryAndDlq(event = "some-event",
retryWhen = { IllegalArgumentException.class, RuntimeException.class },
discartWhen = { BeanDefinitionValidationException.class, NoSuchBeanDefinitionException.class },
directToDlqWhen = { CriticalException.class })
Something like that.
@andrelugomes , IMO it is really nice!
Also, it would be nice if we had an option to define if the exception verification should use the instanceof
operator to allow it to capture children.
So if we use checkInheritance = true, retryWhen = { IllegalArgumentException.class }
then it should capture NumberFormatException.
I've started an implementation for this feature and also included some testing.
https://github.com/wesleyegberto/spring-rabbitmq-tuning/tree/issue-14
@wesleyegberto really nice suggestion!!
Thank you very much for your help!
Just commenting some thoughts about this:
1) Checking priority that should be used In my commit I used the priority bellow, as you can check here.
2) Backwards compatibility
In the commit I kept the compatibility by doing this, allowing this code @EnableRabbitRetryAndDlq(event = "some-event")
to work without modifications.
By doing so, and if the lib uses the checking priority defined in 1, it won't allow this code to work @EnableRabbitRetryAndDlq(event = "some-event", directToDlqWhen = NumberFormatException.class)
(case where we would ignore only one exception and retry any other) because the code exceptions.contains(Exception.class)
would be true before the DLQ list checking.
Here is a test case to demonstrate.
The priority bellow solves the problem:
IMO the DLQ list should be verified before as I think we would define the exceptions of our retry list.
@wesleyegberto I think you are already implemented this feature. Can you open the PR please?
By doing so, and if the lib uses the checking priority defined in 1, it won't allow this code to work @EnableRabbitRetryAndDlq(event = "some-event", directToDlqWhen = NumberFormatException.class) (case where we would ignore only one exception and retry any other) because the code exceptions.contains(Exception.class) would be true before the DLQ list checking.
About this, we should verify only if we have the argument.
Example:
@EnableRabbitRetryAndDlq(event = "some-event")
-> Will retry the children of Exception.class
@EnableRabbitRetryAndDlq(event = "some-event", directToDlqWhen = NumberFormatException.class)
-> Will verify if exceptions
is null, if it is, we need to check only discardWhen
@wesleyegberto, based on your code, I finalized the task!
Thank you very much!
I'm looking forward to merge your other fix!
Steps:
1: Create an attribute in the @EnableRabbitRetryAndDlq annotation for the Exceptions that will be discarded after the max attempts.
https://github.com/Tradeshift/spring-rabbitmq-tuning/blob/master/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlq.java#L14 2: Change the logic that is responsible to choose which message should go to Retry queue.
https://github.com/Tradeshift/spring-rabbitmq-tuning/blob/master/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlqAspect.java#L48 Example: