avimas commented on a change in pull request #6862:
URL: https://github.com/apache/pulsar/pull/6862#discussion_r419102917



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java
##########
@@ -95,7 +95,16 @@ protected ConsumerBase(PulsarClientImpl client, String 
topic, ConsumerConfigurat
         this.schema = schema;
         this.interceptors = interceptors;
         if (conf.getBatchReceivePolicy() != null) {
-            this.batchReceivePolicy = conf.getBatchReceivePolicy();
+            if (conf.getBatchReceivePolicy().getMaxNumMessages() > 
this.maxReceiverQueueSize) {
+                BatchReceivePolicy batchReceivePolicy = 
conf.getBatchReceivePolicy();
+                this.batchReceivePolicy = BatchReceivePolicy.builder()
+                        .maxNumMessages(this.maxReceiverQueueSize)
+                        .maxNumBytes(batchReceivePolicy.getMaxNumBytes())
+                        .timeout((int)batchReceivePolicy.getTimeoutMs()/1000, 
TimeUnit.SECONDS)
+                        .build();
+            } else {
+                this.batchReceivePolicy = conf.getBatchReceivePolicy();
+            }
         } else {
             this.batchReceivePolicy = BatchReceivePolicy.DEFAULT_POLICY;

Review comment:
       The above solution is correct but it users can get confused to see their 
batchRecieve policy configuration has changed 
   Why not changing the function hasEnoughMessagesForBatchReceive to return 
true when 
   incomingMessages.size() >= maxReceiverQueueSize ?
   
    protected boolean hasEnoughMessagesForBatchReceive() {
           if (batchReceivePolicy.getMaxNumMessages() <= 0 && 
batchReceivePolicy.getMaxNumBytes() <= 0) {
               return false;
           }
           return (batchReceivePolicy.getMaxNumMessages() > 0 && 
incomingMessages.size() >= batchReceivePolicy.getMaxNumMessages())
                   || (batchReceivePolicy.getMaxNumBytes() > 0 && 
INCOMING_MESSAGES_SIZE_UPDATER.get(this) >= 
batchReceivePolicy.getMaxNumBytes()) || (incomingMessages.size() >= 
maxReceiverQueueSize);
       }
   




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