Package org.apache.pulsar.client.api
Interface Reader
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
ReaderV1Impl
A Reader can be used to scan through all the messages currently available in a topic.
-
Method Summary
Modifier and TypeMethodDescriptionAsynchronously close the reader and stop the broker to push more messages.getTopic()booleanCheck if there is any message available to read from the current position.Asynchronously Check if there is message that has been published successfully to the broker in the topic.booleanReturn true if the topic was terminated and this reader has reached the end of the topic.booleanorg.apache.pulsar.client.api.Message<byte[]>readNext()Read the next message in the topic.org.apache.pulsar.client.api.Message<byte[]>Read the next message in the topic waiting for a maximum of timeout time units.CompletableFuture<org.apache.pulsar.client.api.Message<byte[]>>
-
Method Details
-
getTopic
String getTopic()- Returns:
- the topic from which this reader is reading from
-
readNext
org.apache.pulsar.client.api.Message<byte[]> readNext() throws org.apache.pulsar.client.api.PulsarClientExceptionRead the next message in the topic.- Returns:
- the next message
- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
readNext
org.apache.pulsar.client.api.Message<byte[]> readNext(int timeout, TimeUnit unit) throws org.apache.pulsar.client.api.PulsarClientException Read the next message in the topic waiting for a maximum of timeout time units. Returns null if no message is received in that time.- Returns:
- the next message(Could be null if none received in time)
- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
readNextAsync
CompletableFuture<org.apache.pulsar.client.api.Message<byte[]>> readNextAsync() -
closeAsync
CompletableFuture<Void> closeAsync()Asynchronously close the reader and stop the broker to push more messages.- Returns:
- a future that can be used to track the completion of the operation
-
hasReachedEndOfTopic
boolean hasReachedEndOfTopic()Return true if the topic was terminated and this reader has reached the end of the topic. -
hasMessageAvailable
boolean hasMessageAvailable() throws org.apache.pulsar.client.api.PulsarClientExceptionCheck if there is any message available to read from the current position.- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
hasMessageAvailableAsync
CompletableFuture<Boolean> hasMessageAvailableAsync()Asynchronously Check if there is message that has been published successfully to the broker in the topic. -
isConnected
boolean isConnected()- Returns:
- Whether the reader is connected to the broker
-