Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Add aws s3:// uri support #565

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix duplicate error logging when processing exception thrown in SQS l…
…istener.

This commit fixes this issue by delegating exception processing to
AbstractMethodMessageHandler only when there is a configured handler.
If there is none, exception is logged.

Fixes gh-394
Closes gh-465

Co-authored-by: Maciej Walkowiak <walkowiak.maciej@yahoo.com>
  • Loading branch information
2 people authored and tmnuwan12 committed Jun 7, 2020
commit a5b295fa03d488934fa357cabce7a5f708d7e410
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.handler.invocation.InvocableHandlerMethod;
import org.springframework.util.ClassUtils;
import org.springframework.util.comparator.ComparableComparator;
import org.springframework.validation.Errors;
Expand Down Expand Up @@ -233,7 +234,15 @@ protected void handleNoMatch(Set<MappingInformation> ts, String lookupDestinatio
@Override
protected void processHandlerMethodException(HandlerMethod handlerMethod,
Exception ex, Message<?> message) {
super.processHandlerMethodException(handlerMethod, ex, message);
InvocableHandlerMethod exceptionHandlerMethod = getExceptionHandlerMethod(
handlerMethod, ex);
if (exceptionHandlerMethod != null) {
super.processHandlerMethodException(handlerMethod, ex, message);
}
else {
this.logger.error("An exception occurred while invoking the handler method",
ex);
}
throw new MessagingException(
"An exception occurred while invoking the handler method", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public void run() {
applyDeletionPolicyOnSuccess(receiptHandle);
}
catch (MessagingException messagingException) {
applyDeletionPolicyOnError(receiptHandle, messagingException);
applyDeletionPolicyOnError(receiptHandle);
}
}

Expand All @@ -430,17 +430,12 @@ private void applyDeletionPolicyOnSuccess(String receiptHandle) {
}
}

private void applyDeletionPolicyOnError(String receiptHandle,
MessagingException messagingException) {
private void applyDeletionPolicyOnError(String receiptHandle) {
if (this.deletionPolicy == SqsMessageDeletionPolicy.ALWAYS
|| (this.deletionPolicy == SqsMessageDeletionPolicy.NO_REDRIVE
&& !this.hasRedrivePolicy)) {
deleteMessage(receiptHandle);
}
else if (this.deletionPolicy == SqsMessageDeletionPolicy.ON_SUCCESS) {
getLogger().error("Exception encountered while processing message.",
messagingException);
}
}

private void deleteMessage(String receiptHandle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.springframework.messaging.support.MessageBuilder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -566,6 +567,40 @@ public void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_
.containsAll(Arrays.asList("queueOne", "queueTwo"))).isTrue();
}

@Test
public void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustBeLogged() {
// Arrange
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("sqsListenerWithoutMessageExceptionHandler",
SqsListenerWithoutMessageExceptionHandler.class);
applicationContext.registerBeanDefinition("queueMessageHandler",
getQueueMessageHandlerBeanDefinition());
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);

LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
Logger log = logContext.getLogger(QueueMessageHandler.class);
log.setLevel(Level.ERROR);
log.addAppender(appender);
appender.setContext(log.getLoggerContext());

// Act
try {
messageHandler.handleMessage(MessageBuilder.withPayload("testContent")
.setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive")
.build());
fail();
}
catch (MessagingException e) {
// ignore
}

// Assert
assertThat(appender.list).hasSize(1);
}

@SuppressWarnings("UnusedDeclaration")
private static class IncomingMessageHandler {

Expand Down Expand Up @@ -604,6 +639,15 @@ private String getLastReceivedMessage() {

}

private static class SqsListenerWithoutMessageExceptionHandler {

@SqsListener("receive")
public String receive(String value) {
throw new RuntimeException("test exception");
}

}

private static class IncomingMessageHandlerWithMultipleQueueNames {

private String lastReceivedMessage;
Expand Down