hangc0276 commented on a change in pull request #11455:
URL: https://github.com/apache/pulsar/pull/11455#discussion_r683436909



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java
##########
@@ -895,24 +897,27 @@ private void pendingBatchReceiveTask(Timeout timeout) 
throws Exception {
     protected void triggerListener() {
         // Trigger the notification on the message listener in a separate 
thread to avoid blocking the networking
         // thread while the message processing happens
-        Message<T> msg;
-        do {
-            try {
-                msg = internalReceive(0, TimeUnit.MILLISECONDS);
+        try {
+            // Control executor to call MessageListener one by one.
+            if (executorQueueSize.get() < 1) {
+                Message<T> msg = internalReceive(0, TimeUnit.MILLISECONDS);

Review comment:
       we can mark `msg` as `final` and delete the `finalMsg` variable.

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java
##########
@@ -895,24 +897,27 @@ private void pendingBatchReceiveTask(Timeout timeout) 
throws Exception {
     protected void triggerListener() {
         // Trigger the notification on the message listener in a separate 
thread to avoid blocking the networking
         // thread while the message processing happens
-        Message<T> msg;
-        do {
-            try {
-                msg = internalReceive(0, TimeUnit.MILLISECONDS);
+        try {
+            // Control executor to call MessageListener one by one.
+            if (executorQueueSize.get() < 1) {
+                Message<T> msg = internalReceive(0, TimeUnit.MILLISECONDS);
                 if (msg != null) {
                     final Message<T> finalMsg = msg;
+                    executorQueueSize.incrementAndGet();
                     if (SubscriptionType.Key_Shared == 
conf.getSubscriptionType()) {
                         
executorProvider.getExecutor(peekMessageKey(finalMsg)).execute(() ->
                                 callMessageListener(finalMsg));
                     } else {
-                        getExecutor(msg).execute(() -> 
callMessageListener(finalMsg));
+                        getExecutor(msg).execute(() -> {
+                            callMessageListener(finalMsg);
+                        });
                     }
                 }
-            } catch (PulsarClientException e) {
-                log.warn("[{}] [{}] Failed to dequeue the message for 
listener", topic, subscription, e);
-                return;
             }
-        } while (msg != null);
+        } catch (Exception e) {

Review comment:
       Why use Exception instead of PulsarClientException?




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to