Package org.apache.pulsar.client.api.v5
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 Summary
Modifier and TypeMethodDescriptionaccessMode(ProducerAccessMode accessMode) Access mode for this producer on the topic.batchingPolicy(BatchingPolicy policy) Configure message batching.blockIfQueueFull(boolean blockIfQueueFull) Whether the producer should block when the pending message queue is full, rather than failing immediately.chunkingPolicy(ChunkingPolicy policy) Enable chunking for large messages that exceed the broker's max message size.compressionPolicy(CompressionPolicy policy) Configure compression for message payloads.create()Create the producer, blocking until it is ready.Create the producer asynchronously.Configure end-to-end message encryption.initialSequenceId(long initialSequenceId) Set the initial sequence ID for producer message deduplication.producerName(String producerName) Set a custom producer name.properties(Map<String, String> properties) Add multiple properties to the producer metadata.Add a single property to the producer metadata.sendTimeout(Duration timeout) Timeout for a send operation.The topic to produce to.
-
Method Details
-
create
Create the producer, blocking until it is ready.- Returns:
- the configured
Producerinstance - 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
CompletableFuturethat completes with the configuredProducer, or completes exceptionally withPulsarClientExceptionon failure
-
topic
The topic to produce to. This is required and must be set before callingcreate().- Parameters:
topicName- the fully qualified topic name (e.g.topic://tenant/namespace/my-topic)- Returns:
- this builder instance for chaining
-
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
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
Timeout for a send operation. If the message is not acknowledged by the broker within this duration, the send future completes exceptionally. A value ofDuration.ZEROdisables the timeout.- Parameters:
timeout- the send timeout duration- Returns:
- this builder instance for chaining
-
blockIfQueueFull
Whether the producer should block when the pending message queue is full, rather than failing immediately. Default istrue.- Parameters:
blockIfQueueFull-trueto block,falseto fail immediately- Returns:
- this builder instance for chaining
-
compressionPolicy
Configure compression for message payloads.- Parameters:
policy- the compression policy- Returns:
- this builder instance for chaining
- See Also:
-
batchingPolicy
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
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
Configure end-to-end message encryption.- Parameters:
policy- the producer-side encryption policy- Returns:
- this builder instance for chaining
- See Also:
-
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
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 keyvalue- the property value- Returns:
- this builder instance for chaining
-
properties
Add multiple properties to the producer metadata.- Parameters:
properties- a map of property key-value pairs- Returns:
- this builder instance for chaining
-