public interface ReaderBuilder<T> extends Cloneable
ReaderBuilder
is used to configure and create instances of Reader
.PulsarClient.newReader()
Modifier and Type | Method and Description |
---|---|
ReaderBuilder<T> |
clone()
Create a copy of the current
ReaderBuilder . |
Reader<T> |
create()
Finalize the creation of the
Reader instance. |
CompletableFuture<Reader<T>> |
createAsync()
Finalize the creation of the
Reader instance in asynchronous mode. |
ReaderBuilder<T> |
cryptoFailureAction(ConsumerCryptoFailureAction action)
Sets the
ConsumerCryptoFailureAction to specify |
ReaderBuilder<T> |
cryptoKeyReader(CryptoKeyReader cryptoKeyReader)
Sets a
CryptoKeyReader to decrypt the message payloads. |
ReaderBuilder<T> |
loadConf(Map<String,Object> config)
Load the configuration from provided config map.
|
ReaderBuilder<T> |
readCompacted(boolean readCompacted)
If enabled, the reader will read messages from the compacted topic rather than reading the full message backlog
of the topic.
|
ReaderBuilder<T> |
readerListener(ReaderListener<T> readerListener)
Sets a
ReaderListener for the reader |
ReaderBuilder<T> |
readerName(String readerName)
Specify a reader name.
|
ReaderBuilder<T> |
receiverQueueSize(int receiverQueueSize)
Sets the size of the consumer receive queue.
|
ReaderBuilder<T> |
startMessageId(MessageId startMessageId)
The initial reader positioning is done by specifying a message id.
|
ReaderBuilder<T> |
subscriptionRolePrefix(String subscriptionRolePrefix)
Set the subscription role prefix.
|
ReaderBuilder<T> |
topic(String topicName)
Specify the topic this reader will read from.
|
Reader<T> create() throws PulsarClientException
Reader
instance.
This method will block until the reader is created successfully or an exception is thrown.
PulsarClientException
- if the reader creation failsCompletableFuture<Reader<T>> createAsync()
Reader
instance in asynchronous mode.
This method will return a CompletableFuture
that can be used to access the instance when it's ready.
PulsarClientException
- if the reader creation failsReaderBuilder<T> loadConf(Map<String,Object> config)
Example:
Map<String, Object> config = new HashMap<>();
config.put("topicName", "test-topic");
config.put("receiverQueueSize", 2000);
ReaderBuilder<byte[]> builder = ...;
builder = builder.loadConf(config);
Reader<byte[]> reader = builder.create();
config
- configuration to loadReaderBuilder<T> clone()
ReaderBuilder
.
Cloning the builder can be used to share an incomplete configuration and specialize it multiple times. For example:
ReaderBuilder<String> builder = client.newReader(Schema.STRING)
.readerName("my-reader")
.receiverQueueSize(10);
Reader<String> reader1 = builder.clone().topic("topic-1").create();
Reader<String> reader2 = builder.clone().topic("topic-2").create();
ReaderBuilder<T> topic(String topicName)
This argument is required when constructing the reader.
topicName
- the name of the topicReaderBuilder<T> startMessageId(MessageId startMessageId)
MessageId.earliest
: Start reading from the earliest message available in the topicMessageId.latest
: Start reading from end of the topic. The first message read will be the one
published *after* the creation of the builderMessageId
: Position the reader on a particular message. The first message read will be the one
immediately *after* the specified messagestartMessageId
- the message id where the reader will be initially positioned onReaderBuilder<T> readerListener(ReaderListener<T> readerListener)
ReaderListener
for the reader
When a ReaderListener
is set, application will receive messages through it. Calls to
Reader.readNext()
will not be allowed.
readerListener
- the listener objectReaderBuilder<T> cryptoKeyReader(CryptoKeyReader cryptoKeyReader)
CryptoKeyReader
to decrypt the message payloads.cryptoKeyReader
- CryptoKeyReader objectReaderBuilder<T> cryptoFailureAction(ConsumerCryptoFailureAction action)
ConsumerCryptoFailureAction
to specifyaction
- The action to take when the decoding failsReaderBuilder<T> receiverQueueSize(int receiverQueueSize)
The consumer receive queue controls how many messages can be accumulated by the Consumer
before the
application calls Consumer.receive()
. Using a higher value could potentially increase the consumer
throughput at the expense of bigger memory utilization.
Default value is 1000
messages and should be good for most use cases.
receiverQueueSize
- the new receiver queue size valueReaderBuilder<T> readerName(String readerName)
The reader name is purely informational and can used to track a particular reader in the reported stats. By default a randomly generated name is used.
readerName
- the name to use for the readerReaderBuilder<T> subscriptionRolePrefix(String subscriptionRolePrefix)
subscriptionRolePrefix
- ReaderBuilder<T> readCompacted(boolean readCompacted)
readCompacted can only be enabled when reading from a persistent topic. Attempting to enable it on non-persistent
topics will lead to the reader create call throwing a PulsarClientException
.
readCompacted
- whether to read from the compacted topicCopyright © 2017–2019 Apache Software Foundation. All rights reserved.