Interface ProducerBuilder<T>

Type Parameters:
T - the type of message values the producer will send

public interface ProducerBuilder<T>
Builder for configuring and creating a Producer.
  • Method Details

    • create

      Producer<T> create() throws PulsarClientException
      Create the producer, blocking until it is ready.
      Returns:
      the configured Producer instance
      Throws:
      PulsarClientException - if the producer cannot be created (e.g. topic does not exist, authorization failure, or connection error)
    • createAsync

      CompletableFuture<Producer<T>> createAsync()
      Create the producer asynchronously.
      Returns:
      a CompletableFuture that completes with the configured Producer, or completes exceptionally with PulsarClientException on failure
    • topic

      ProducerBuilder<T> topic(String topicName)
      The topic to produce to. This is required and must be set before calling create().
      Parameters:
      topicName - the fully qualified topic name (e.g. topic://tenant/namespace/my-topic)
      Returns:
      this builder instance for chaining
    • producerName

      ProducerBuilder<T> producerName(String producerName)
      Set a custom producer name. If not set, the broker assigns a unique name. The producer name is used for message deduplication and appears in broker logs.
      Parameters:
      producerName - the producer name
      Returns:
      this builder instance for chaining
    • accessMode

      ProducerBuilder<T> accessMode(ProducerAccessMode accessMode)
      Access mode for this producer on the topic.
      Parameters:
      accessMode - the access mode (e.g. ProducerAccessMode.SHARED, ProducerAccessMode.EXCLUSIVE)
      Returns:
      this builder instance for chaining
    • sendTimeout

      ProducerBuilder<T> sendTimeout(Duration timeout)
      Timeout for a send operation. If the message is not acknowledged by the broker within this duration, the send future completes exceptionally. A value of Duration.ZERO disables the timeout.
      Parameters:
      timeout - the send timeout duration
      Returns:
      this builder instance for chaining
    • blockIfQueueFull

      ProducerBuilder<T> blockIfQueueFull(boolean blockIfQueueFull)
      Whether the producer should block when the pending message queue is full, rather than failing immediately. Default is true.
      Parameters:
      blockIfQueueFull - true to block, false to fail immediately
      Returns:
      this builder instance for chaining
    • compressionPolicy

      ProducerBuilder<T> compressionPolicy(CompressionPolicy policy)
      Configure compression for message payloads.
      Parameters:
      policy - the compression policy
      Returns:
      this builder instance for chaining
      See Also:
    • batchingPolicy

      ProducerBuilder<T> batchingPolicy(BatchingPolicy policy)
      Configure message batching. When enabled, the producer groups multiple messages into a single broker request to improve throughput.
      Parameters:
      policy - the batching policy
      Returns:
      this builder instance for chaining
      See Also:
    • chunkingPolicy

      ProducerBuilder<T> chunkingPolicy(ChunkingPolicy policy)
      Enable chunking for large messages that exceed the broker's max message size.
      Parameters:
      policy - the chunking policy
      Returns:
      this builder instance for chaining
    • encryptionPolicy

      ProducerBuilder<T> encryptionPolicy(ProducerEncryptionPolicy policy)
      Configure end-to-end message encryption.
      Parameters:
      policy - the producer-side encryption policy
      Returns:
      this builder instance for chaining
      See Also:
    • initialSequenceId

      ProducerBuilder<T> initialSequenceId(long initialSequenceId)
      Set the initial sequence ID for producer message deduplication. Subsequent messages are assigned incrementing sequence IDs starting from this value.
      Parameters:
      initialSequenceId - the starting sequence ID
      Returns:
      this builder instance for chaining
    • property

      ProducerBuilder<T> property(String key, String value)
      Add a single property to the producer metadata. Properties are sent to the broker and can be used for filtering and identification.
      Parameters:
      key - the property key
      value - the property value
      Returns:
      this builder instance for chaining
    • properties

      ProducerBuilder<T> properties(Map<String,String> properties)
      Add multiple properties to the producer metadata.
      Parameters:
      properties - a map of property key-value pairs
      Returns:
      this builder instance for chaining