You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/12/31 13:12:36 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #9102: [pulsar-client] Fix redeliverUnacknowledgedMessages may block timer thread cause serious problem

codelipenghui commented on a change in pull request #9102:
URL: https://github.com/apache/pulsar/pull/9102#discussion_r550479879



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -1843,18 +1812,29 @@ private boolean processPossibleToDLQ(MessageIdImpl messageId) {
                 }
             }
             if (deadLetterProducer != null) {
-                try {
-                    for (MessageImpl<T> message : deadLetterMessages) {
-                        deadLetterProducer.newMessage()
-                                .value(message.getValue())
-                                .properties(message.getProperties())
-                                .send();
-                    }
-                    acknowledge(messageId);
-                    return true;
-                } catch (Exception e) {
-                    log.error("Send to dead letter topic exception with topic: {}, messageId: {}", deadLetterProducer.getTopic(), messageId, e);
+                for (MessageImpl<T> message : deadLetterMessages) {
+                    deadLetterProducer.newMessage()
+                            .value(message.getValue())
+                            .properties(message.getProperties())
+                            .sendAsync()
+                            .whenComplete((msgId, ex) -> {
+                                if (ex != null) {
+                                    log.error("Send to dead letter topic exception with topic: {}, messageId: {}",
+                                            deadLetterProducer.getTopic(), messageId, ex);
+                                    return;
+                                }
+
+                                log.debug("Redeliver dead letter message topic: {}, messageId: {} to dead letter topic with topic: {}, messageId: {}",
+                                        message.getTopicName(), messageId, deadLetterProducer.getTopic(), msgId);
+                                try {
+                                    acknowledge(messageId);
+                                } catch (Exception e) {
+                                    log.error("Acknowledge dead letter message exception with topic: {}, messageId: {}",
+                                            message.getTopicName(), messageId);
+                                }
+                            });
                 }
+                return true;

Review comment:
       You can't return true here because this will always return true even if the message write to the dead letter topic fails. This is used to filter out the messages that should not be delivered.
   
   I think maybe you should change the method `processPossibleToDLQ` to `processPossibleToDLQAsync`.

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -107,6 +60,22 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.util.*;

Review comment:
       Please avoid use import .*




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org