Class TopicMessageQuery

java.lang.Object
com.hedera.hashgraph.sdk.TopicMessageQuery

public final class TopicMessageQuery extends Object
Subscribe to a topic ID's messages from a mirror node. You will receive all messages for the specified topic or within the defined start and end time.
  • Constructor Details

    • TopicMessageQuery

      public TopicMessageQuery()
      Constructor.
  • Method Details

    • setTopicId

      public TopicMessageQuery setTopicId(TopicId topicId)
      Assign the topic id.
      Parameters:
      topicId - the topic id
      Returns:
      this
    • setStartTime

      public TopicMessageQuery setStartTime(Instant startTime)
      Assign the start time.
      Parameters:
      startTime - the start time
      Returns:
      this
    • setEndTime

      public TopicMessageQuery setEndTime(Instant endTime)
      Assign the end time.
      Parameters:
      endTime - the end time
      Returns:
      this
    • setLimit

      public TopicMessageQuery setLimit(long limit)
      Assign the number of messages to return.
      Parameters:
      limit - the number of messages to return
      Returns:
      this
    • setCompletionHandler

      public TopicMessageQuery setCompletionHandler(Runnable completionHandler)
      Assign the call back function.
      Parameters:
      completionHandler - the call back function
      Returns:
      this
    • setErrorHandler

      public TopicMessageQuery setErrorHandler(BiConsumer<Throwable,TopicMessage> errorHandler)
      Assign the error handler does not return a value.
      Parameters:
      errorHandler - the error handler
      Returns:
      this
    • setMaxAttempts

      public TopicMessageQuery setMaxAttempts(int maxAttempts)
      Assign the maximum number of attempts.
      Parameters:
      maxAttempts - the max attempts
      Returns:
      this
    • setMaxBackoff

      public TopicMessageQuery setMaxBackoff(Duration maxBackoff)
      The maximum backoff in milliseconds.
      Parameters:
      maxBackoff - the maximum backoff
      Returns:
      this
    • setRetryHandler

      public TopicMessageQuery setRetryHandler(Predicate<Throwable> retryHandler)
      Assign the retry handler.
      Parameters:
      retryHandler - the retry handler
      Returns:
      this
    • subscribe

      public SubscriptionHandle subscribe(Client client, Consumer<TopicMessage> onNext)
      Subscribe to the topic.
      Parameters:
      client - the configured client
      onNext - the consumer
      Returns:
      the subscription handle