Package org.apache.pulsar.client.api.v5
Interface StreamConsumerBuilder<T>
- Type Parameters:
T- the type of message values the consumer will receive
public interface StreamConsumerBuilder<T>
Builder for configuring and creating a
StreamConsumer.-
Method Summary
Modifier and TypeMethodDescriptionacknowledgmentGroupTime(Duration delay) How frequently cumulative acknowledgments are flushed to the broker.consumerName(String consumerName) A custom name for this consumer instance.Configure end-to-end message encryption for decryption.Subscribe to every scalable topic under a namespace.Subscribe to scalable topics under a namespace whose properties match every key/value pair inpropertyFilters(AND semantics).properties(Map<String, String> properties) Add multiple properties to the consumer metadata.Add a single property to the consumer metadata.readCompacted(boolean readCompacted) Whether to read from the compacted topic (only latest value per key).replicateSubscriptionState(boolean replicate) Enable replication of subscription state across geo-replicated clusters.Subscribe and create the stream consumer, blocking until ready.Subscribe and create the stream consumer asynchronously.Initial position when the subscription is first created (no existing cursor).subscriptionName(String subscriptionName) The subscription name.subscriptionProperties(Map<String, String> properties) Properties to attach to the subscription.Subscribe to a single scalable topic by name.
-
Method Details
-
subscribe
Subscribe and create the stream consumer, blocking until ready.- Returns:
- the created
StreamConsumer - Throws:
PulsarClientException- if the subscription fails or a connection error occurs
-
subscribeAsync
CompletableFuture<StreamConsumer<T>> subscribeAsync()Subscribe and create the stream consumer asynchronously.- Returns:
- a
CompletableFuturethat completes with the createdStreamConsumer
-
topic
Subscribe to a single scalable topic by name.- Parameters:
topicName- the fully-qualified topic name (e.g.topic://tenant/ns/name)- Returns:
- this builder instance for chaining
-
namespace
Subscribe to every scalable topic under a namespace. The matching set follows live: when topics are created in or deleted from the namespace, the consumer attaches / detaches automatically.- Parameters:
namespace- the namespace intenant/namespaceform- Returns:
- this builder instance for chaining
-
namespace
Subscribe to scalable topics under a namespace whose properties match every key/value pair inpropertyFilters(AND semantics). An empty map is equivalent tonamespace(String)— every topic in the namespace. The matching set follows live as topic properties change.- Parameters:
namespace- the namespace intenant/namespaceformpropertyFilters- property name/value pairs that all must match- Returns:
- this builder instance for chaining
-
subscriptionName
The subscription name.- Parameters:
subscriptionName- the subscription name- Returns:
- this builder instance for chaining
-
subscriptionProperties
Properties to attach to the subscription.- Parameters:
properties- the subscription properties- Returns:
- this builder instance for chaining
-
subscriptionInitialPosition
Initial position when the subscription is first created (no existing cursor).- Parameters:
position- the initial position- Returns:
- this builder instance for chaining
-
consumerName
A custom name for this consumer instance.- Parameters:
consumerName- the consumer name- Returns:
- this builder instance for chaining
-
acknowledgmentGroupTime
How frequently cumulative acknowledgments are flushed to the broker.- Parameters:
delay- the acknowledgment group time- Returns:
- this builder instance for chaining
-
readCompacted
Whether to read from the compacted topic (only latest value per key).- Parameters:
readCompacted-trueto read from the compacted topic- Returns:
- this builder instance for chaining
-
replicateSubscriptionState
Enable replication of subscription state across geo-replicated clusters.- Parameters:
replicate-trueto replicate subscription state- Returns:
- this builder instance for chaining
-
encryptionPolicy
Configure end-to-end message encryption for decryption.- Parameters:
policy- the encryption policy to use- Returns:
- this builder instance for chaining
- See Also:
-
property
Add a single property to the consumer metadata.- Parameters:
key- the property keyvalue- the property value- Returns:
- this builder instance for chaining
-
properties
Add multiple properties to the consumer metadata.- Parameters:
properties- the properties to add- Returns:
- this builder instance for chaining
-