Class BatchingPolicy

java.lang.Object
org.apache.pulsar.client.api.v5.config.BatchingPolicy

public final class BatchingPolicy extends Object
Configuration for producer message batching.

When batching is enabled, the producer groups multiple messages into a single broker request to improve throughput. A batch is flushed when any of the configured thresholds is reached.

Construct via builder(), or use ofDisabled() to opt out.

  • Method Details

    • enabled

      public boolean enabled()
      Returns:
      whether batching is enabled
    • maxPublishDelay

      public Duration maxPublishDelay()
      Returns:
      the maximum time to wait before flushing a batch
    • maxMessages

      public int maxMessages()
      Returns:
      the maximum number of messages in a single batch
    • maxSize

      public MemorySize maxSize()
      Returns:
      the maximum size of a single batch
    • ofDisabled

      public static BatchingPolicy ofDisabled()
      Batching disabled.
      Returns:
      a BatchingPolicy with batching disabled
    • builder

      public static BatchingPolicy.Builder builder()
      Returns:
      a new builder for constructing a BatchingPolicy