@Test void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTypeAcknowledgment_warningMustBeLogged() throws Exception { QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); Method receiveMethod = SqsListenerDeletionPolicyNeverNoAcknowledgment.class .getMethod("receive", String.class); LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory(); ListAppender<ILoggingEvent> appender = new ListAppender<>(); appender.start(); Logger log = logContext.getLogger(QueueMessageHandler.class); log.setLevel(Level.WARN); log.addAppender(appender); appender.setContext(log.getLoggerContext()); queueMessageHandler.getMappingForMethod(receiveMethod, null); ILoggingEvent loggingEvent = appender.list.get(0); assertThat(loggingEvent.getLevel()).isSameAs(Level.WARN); assertThat(loggingEvent.getMessage().contains("receive")).isTrue(); assertThat(loggingEvent.getMessage().contains( "org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest$SqsListener" + "DeletionPolicyNeverNoAcknowledgment")).isTrue(); }
@Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method, SqsListener.class); if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) { SqsMessageDeletionPolicy tempDeletionPolicy = sqsListenerAnnotation .deletionPolicy() == SqsMessageDeletionPolicy.DEFAULT ? sqsMessageDeletionPolicy : sqsListenerAnnotation.deletionPolicy(); if (tempDeletionPolicy == SqsMessageDeletionPolicy.NEVER && hasNoAcknowledgmentParameter(method.getParameterTypes())) { this.logger.warn("Listener method '" + method.getName() + "' in type '" + method.getDeclaringClass().getName() + "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment."); } return new MappingInformation( resolveDestinationNames(sqsListenerAnnotation.value()), tempDeletionPolicy); } MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation != null && messageMappingAnnotation.value().length > 0) { return new MappingInformation( resolveDestinationNames(messageMappingAnnotation.value()), SqsMessageDeletionPolicy.ALWAYS); } return null; }
QueueMessageHandler extends AbstractMethodMessageHandler<QueueMessageHandler.MappingInformation> { @Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method, SqsListener.class); if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) { SqsMessageDeletionPolicy tempDeletionPolicy = sqsListenerAnnotation .deletionPolicy() == SqsMessageDeletionPolicy.DEFAULT ? sqsMessageDeletionPolicy : sqsListenerAnnotation.deletionPolicy(); if (tempDeletionPolicy == SqsMessageDeletionPolicy.NEVER && hasNoAcknowledgmentParameter(method.getParameterTypes())) { this.logger.warn("Listener method '" + method.getName() + "' in type '" + method.getDeclaringClass().getName() + "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment."); } return new MappingInformation( resolveDestinationNames(sqsListenerAnnotation.value()), tempDeletionPolicy); } MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation != null && messageMappingAnnotation.value().length > 0) { return new MappingInformation( resolveDestinationNames(messageMappingAnnotation.value()), SqsMessageDeletionPolicy.ALWAYS); } return null; } }
QueueMessageHandler extends AbstractMethodMessageHandler<QueueMessageHandler.MappingInformation> { @Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method, SqsListener.class); if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) { SqsMessageDeletionPolicy tempDeletionPolicy = sqsListenerAnnotation .deletionPolicy() == SqsMessageDeletionPolicy.DEFAULT ? sqsMessageDeletionPolicy : sqsListenerAnnotation.deletionPolicy(); if (tempDeletionPolicy == SqsMessageDeletionPolicy.NEVER && hasNoAcknowledgmentParameter(method.getParameterTypes())) { this.logger.warn("Listener method '" + method.getName() + "' in type '" + method.getDeclaringClass().getName() + "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment."); } return new MappingInformation( resolveDestinationNames(sqsListenerAnnotation.value()), tempDeletionPolicy); } MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation != null && messageMappingAnnotation.value().length > 0) { return new MappingInformation( resolveDestinationNames(messageMappingAnnotation.value()), SqsMessageDeletionPolicy.ALWAYS); } return null; } QueueMessageHandler(List<MessageConverter> messageConverters,
			SqsMessageDeletionPolicy sqsMessageDeletionPolicy);  QueueMessageHandler(); }
QueueMessageHandler extends AbstractMethodMessageHandler<QueueMessageHandler.MappingInformation> { @Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method, SqsListener.class); if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) { SqsMessageDeletionPolicy tempDeletionPolicy = sqsListenerAnnotation .deletionPolicy() == SqsMessageDeletionPolicy.DEFAULT ? sqsMessageDeletionPolicy : sqsListenerAnnotation.deletionPolicy(); if (tempDeletionPolicy == SqsMessageDeletionPolicy.NEVER && hasNoAcknowledgmentParameter(method.getParameterTypes())) { this.logger.warn("Listener method '" + method.getName() + "' in type '" + method.getDeclaringClass().getName() + "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment."); } return new MappingInformation( resolveDestinationNames(sqsListenerAnnotation.value()), tempDeletionPolicy); } MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation != null && messageMappingAnnotation.value().length > 0) { return new MappingInformation( resolveDestinationNames(messageMappingAnnotation.value()), SqsMessageDeletionPolicy.ALWAYS); } return null; } QueueMessageHandler(List<MessageConverter> messageConverters,
			SqsMessageDeletionPolicy sqsMessageDeletionPolicy);  QueueMessageHandler();  }
QueueMessageHandler extends AbstractMethodMessageHandler<QueueMessageHandler.MappingInformation> { @Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { SqsListener sqsListenerAnnotation = AnnotationUtils.findAnnotation(method, SqsListener.class); if (sqsListenerAnnotation != null && sqsListenerAnnotation.value().length > 0) { SqsMessageDeletionPolicy tempDeletionPolicy = sqsListenerAnnotation .deletionPolicy() == SqsMessageDeletionPolicy.DEFAULT ? sqsMessageDeletionPolicy : sqsListenerAnnotation.deletionPolicy(); if (tempDeletionPolicy == SqsMessageDeletionPolicy.NEVER && hasNoAcknowledgmentParameter(method.getParameterTypes())) { this.logger.warn("Listener method '" + method.getName() + "' in type '" + method.getDeclaringClass().getName() + "' has deletion policy 'NEVER' but does not have a parameter of type Acknowledgment."); } return new MappingInformation( resolveDestinationNames(sqsListenerAnnotation.value()), tempDeletionPolicy); } MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation != null && messageMappingAnnotation.value().length > 0) { return new MappingInformation( resolveDestinationNames(messageMappingAnnotation.value()), SqsMessageDeletionPolicy.ALWAYS); } return null; } QueueMessageHandler(List<MessageConverter> messageConverters,
			SqsMessageDeletionPolicy sqsMessageDeletionPolicy);  QueueMessageHandler();   }