Skip to content

Commit

Permalink
Make EnableRabbitRetryAndDlq applicable to ElementType.ANNOTATION_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniobarcelos committed Dec 16, 2019
1 parent 8d26ced commit 9c0d2ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* The <code>discardWhen</code> attribute has higher precedence over <code>exceptions</code> attribute.
*/
@Target(ElementType.METHOD)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface EnableRabbitRetryAndDlq {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -214,6 +218,18 @@ public void should_send_dlq_when_only_directToDlqWhen_exceptions_contains_and_no
verifySentToRetryNeverCalled();
verifyIfDlqWasCalled(1);
}

@Test
@DirectToDqlWhenNumberFormatExceptionListener
public void should_send_dlq_when_only_directToDlqWhen_exceptions_contains_and_no_other_defined_when_it_is_using_a_custom_annotation() throws Throwable {
ProceedingJoinPoint joinPoint = mockJointPointWithDeathAndThrowing(
"should_send_dlq_when_only_directToDlqWhen_exceptions_contains_and_no_other_defined", 1, NumberFormatException.class);

aspect.validateMessage(joinPoint);

verifySentToRetryNeverCalled();
verifyIfDlqWasCalled(1);
}

private void verifySentToRetryNeverCalled() {
verify(queueComponent, never()).sendToRetryOrDlq(any(Message.class), any());
Expand Down Expand Up @@ -283,4 +299,15 @@ private static TunedRabbitProperties createQueueProperties() {
queueProperties.setMaxRetriesAttempts(3);
return queueProperties;
}
}



@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@EnableRabbitRetryAndDlq(event = "some-event",
directToDlqWhen = NumberFormatException.class
)
public @interface DirectToDqlWhenNumberFormatExceptionListener {

}
}

0 comments on commit 9c0d2ed

Please sign in to comment.