Interface Reader

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ReaderV1Impl

public interface Reader extends Closeable
A Reader can be used to scan through all the messages currently available in a topic.
  • 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.PulsarClientException
      Read 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.PulsarClientException
      Check 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