diff --git a/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlq.java b/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlq.java index 98c700a..af431b9 100644 --- a/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlq.java +++ b/src/main/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlq.java @@ -17,7 +17,7 @@ * * The discardWhen attribute has higher precedence over exceptions attribute. */ -@Target(ElementType.METHOD) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface EnableRabbitRetryAndDlq { diff --git a/src/test/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlqAspectTest.java b/src/test/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlqAspectTest.java index feadd7d..7f874c4 100644 --- a/src/test/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlqAspectTest.java +++ b/src/test/java/com/tradeshift/amqp/annotation/EnableRabbitRetryAndDlqAspectTest.java @@ -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; @@ -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()); @@ -283,4 +299,15 @@ private static TunedRabbitProperties createQueueProperties() { queueProperties.setMaxRetriesAttempts(3); return queueProperties; } -} \ No newline at end of file + + + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @EnableRabbitRetryAndDlq(event = "some-event", + directToDlqWhen = NumberFormatException.class + ) + public @interface DirectToDqlWhenNumberFormatExceptionListener { + + } +}