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



##########
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:
       It's not a safe operation since the client might crash before the next 
retry. 
   
   > but make the method processPossibleToDLQ asynchronous will bring many 
other changes to fit async.
   
   Yes, this will introduce more changes, but this is not to introduce some 
irrelevant code. Change the `processPossibleToDLQ` asynchronously will avoid 
the complexity of solving this problem from the root cause




----------------------------------------------------------------
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:
[email protected]


Reply via email to