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 2019/08/10 03:34:04 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #4621: [PIP-38] Support batch receive in java client.

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

 ##########
 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(
 
 Review comment:
   in general I am not in favor of using "number of messages" in any configuration or policies. In a multi-tenant system, message size varies between tenants and applications. so I would actually remove the limit of number of message just rely on number of bytes for a default policy. 
   
   Hence my recommendation would be:
   
   ```
   BatchReceivePolicy DEFAULT_POLICY = new BatchReceivePolicy(-1, 10 * 1024 * 1024, 100, TimeUnit.MILLISECONDS);
   ```

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


With regards,
Apache Git Services