codelipenghui commented on a change in pull request #4621: [PIP-38] Support 
batch receive in java client.
URL: https://github.com/apache/pulsar/pull/4621#discussion_r312740300
 
 

 ##########
 File path: 
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/BatchReceivePolicy.java
 ##########
 @@ -0,0 +1,160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.api;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration for message batch receive {@link Consumer#batchReceive()} 
{@link Consumer#batchReceiveAsync()}.
+ *
+ * Batch receive policy can limit the number and bytes of messages in a single 
batch, and can specify a timeout
+ * for waiting for enough messages for this batch.
+ *
+ * This batch receive will be completed as long as any one of the
+ * conditions(has enough number of messages, has enough of size of messages, 
wait timeout) is met.
+ *
+ * Examples:
+ *
+ * 1.If set maxNumMessages = 10, maxSizeOfMessages = 1MB and without timeout, 
it
+ * means {@link Consumer#batchReceive()} will always wait until there is 
enough messages.
+ *
+ * 2.If set maxNumberOfMessages = 0, maxNumBytes = 0 and timeout = 100ms, it
+ * means {@link Consumer#batchReceive()} will waiting for 100ms whether or not 
there is enough messages.
+ *
+ * Note:
+ * Must specify messages limitation(maxNumMessages, maxNumBytes) or wait 
timeout.
+ * Otherwise, {@link Messages} ingest {@link Message} will never end.
+ *
+ * @since 2.4.1
+ */
+public class BatchReceivePolicy {
+
+    /**
+     * Default batch receive policy
+     *
+     * Max number of messages: 100
+     * Max number of bytes: 10MB
+     * Timeout: 100ms
+     */
+    public static final BatchReceivePolicy DEFAULT_POLICY = new 
BatchReceivePolicy(
+            100, 1024 * 1024 * 10, 100, TimeUnit.MILLISECONDS);
+
+    private BatchReceivePolicy(int maxNumMessages, long maxNumBytes, int 
timeout, TimeUnit timeoutUnit) {
+        this.maxNumMessages = maxNumMessages;
+        this.maxNumBytes = maxNumBytes;
+        this.timeout = timeout;
+        this.timeoutUnit = timeoutUnit;
+    }
+
+    /**
+     * Max number of messages for a single batch receive, 0 or negative means 
no limit.
+     */
+    private int maxNumMessages;
+
+    /**
+     * Max bytes of messages for a single batch receive, 0 or negative means 
no limit.
+     */
+    private long maxNumBytes;
 
 Review comment:
   fix it

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to