From 854e922f325a700d32a18e865dcc26209d5e7409 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 29 Mar 2018 12:17:25 -0400 Subject: [PATCH] GH-141 Fixed DLQ vs local handler inconsistencies Given that is already checking for `properties.getExtension().isRepublishToDlq()` removing the IF from the configuration phase of the adapter with RetryTemplate ensures the consistency of the behavior for cases when local error handler is configured and RetryTemplate is used. Resolves #141 --- .../binder/rabbit/RabbitMessageChannelBinder.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java index ed8c24817..4250aed38 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java @@ -391,9 +391,7 @@ public class RabbitMessageChannelBinder ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(consumerDestination, group, properties); if (properties.getMaxAttempts() > 1) { adapter.setRetryTemplate(buildRetryTemplate(properties)); - if (properties.getExtension().isRepublishToDlq()) { - adapter.setRecoveryCallback(errorInfrastructure.getRecoverer()); - } + adapter.setRecoveryCallback(errorInfrastructure.getRecoverer()); } else { adapter.setErrorMessageStrategy(errorMessageStrategy); @@ -478,13 +476,19 @@ public class RabbitMessageChannelBinder } else if (properties.getMaxAttempts() > 1) { return new MessageHandler() { - private final RejectAndDontRequeueRecoverer recoverer = new RejectAndDontRequeueRecoverer(); @Override public void handleMessage(org.springframework.messaging.Message message) throws MessagingException { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); + /* + * NOTE: The following IF and subsequent ELSE IF should never happen under normal interaction and + * it should always go to the last ELSE + * However, given that this is a handler subscribing to the public channel and that we can't control what + * type of Message may be sent to that channel (user decides to send a Message manually) the 'IF/ELSE IF' provides + * a safety net to handle any message properly. + */ if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message);