|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +#ifndef BATCH_RECEIVE_POLICY_HPP_ |
| 20 | +#define BATCH_RECEIVE_POLICY_HPP_ |
| 21 | + |
| 22 | +#include <pulsar/defines.h> |
| 23 | +#include <memory> |
| 24 | + |
| 25 | +namespace pulsar { |
| 26 | + |
| 27 | +struct BatchReceivePolicyImpl; |
| 28 | + |
| 29 | +/** |
| 30 | + * Configuration for message batch receive {@link Consumer#batchReceive()} {@link |
| 31 | + * Consumer#batchReceiveAsync()}. |
| 32 | + * |
| 33 | + * <p>Batch receive policy can limit the number and bytes of messages in a single batch, and can specify a |
| 34 | + * timeout for waiting for enough messages for this batch. |
| 35 | + * |
| 36 | + * <p>A batch receive action is completed as long as any one of the |
| 37 | + * conditions (the batch has enough number or size of messages, or the waiting timeout is passed) are met. |
| 38 | + * |
| 39 | + * <p>Examples: |
| 40 | + * 1.If set maxNumMessages = 10, maxSizeOfMessages = 1MB and without timeout, it |
| 41 | + * means {@link Consumer#batchReceive()} will always wait until there is enough messages. |
| 42 | + * 2.If set maxNumberOfMessages = 0, maxNumBytes = 0 and timeout = 100ms, it |
| 43 | + * means {@link Consumer#batchReceive()} will wait for 100ms no matter whether there are enough messages. |
| 44 | + * |
| 45 | + * <p>Note: |
| 46 | + * Must specify messages limitation(maxNumMessages, maxNumBytes) or wait timeout. |
| 47 | + * Otherwise, {@link Messages} ingest {@link Message} will never end. |
| 48 | + * |
| 49 | + * @since 2.4.1 |
| 50 | + */ |
| 51 | +class PULSAR_PUBLIC BatchReceivePolicy { |
| 52 | + public: |
| 53 | + /** |
| 54 | + * Default value: {maxNumMessage: -1, maxNumBytes: 10 * 1024 * 1024, timeoutMs: 100} |
| 55 | + */ |
| 56 | + BatchReceivePolicy(); |
| 57 | + |
| 58 | + /** |
| 59 | + * |
| 60 | + * @param maxNumMessage Max num message, if less than 0, it means no limit. |
| 61 | + * @param maxNumBytes Max num bytes, if less than 0, it means no limit. |
| 62 | + * @param timeoutMs If less than 0, it means no limit. |
| 63 | + */ |
| 64 | + BatchReceivePolicy(int maxNumMessage, long maxNumBytes, long timeoutMs); |
| 65 | + |
| 66 | + /** |
| 67 | + * Get max time out ms. |
| 68 | + * |
| 69 | + * @return |
| 70 | + */ |
| 71 | + long getTimeoutMs() const; |
| 72 | + |
| 73 | + /** |
| 74 | + * Get the maximum number of messages. |
| 75 | + * @return |
| 76 | + */ |
| 77 | + int getMaxNumMessages() const; |
| 78 | + |
| 79 | + /** |
| 80 | + * Get max num bytes. |
| 81 | + * @return |
| 82 | + */ |
| 83 | + long getMaxNumBytes() const; |
| 84 | + |
| 85 | + private: |
| 86 | + std::shared_ptr<BatchReceivePolicyImpl> impl_; |
| 87 | +}; |
| 88 | +} // namespace pulsar |
| 89 | + |
| 90 | +#endif /* BATCH_RECEIVE_POLICY_HPP_ */ |
0 commit comments