Skip to main content

Documentation Index

Fetch the complete documentation index at: https://hedera-0c6e0218-mintlify-enhance-hollow-account-docs-97196.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

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. Query Fees

Methods

MethodTypeDescriptionRequirement
setTopicId(<topicId>)TopicIdThe topic ID to subscribe toRequired
setStartTime(<startTime>)InstantThe time to start subscribing to a topic’s messagesOptional
setEndTime(<endTime>)InstantThe time to stop subscribing to a topic’s messagesOptional
setLimit(<limit>)longThe number of messages to returnOptional
subscribe(<client, onNext)SubscriptionHandleClient, Consumer<TopicMessage>Required
//Create the query
new TopicMessageQuery()
    .setTopicId(newTopicId)
    .subscribe(client, topicMessage -> {
        System.out.println("at " + topicMessage.consensusTimestamp + " ( seq = " + topicMessage.sequenceNumber + " ) received topic message of " + topicMessage.contents.length + " bytes");
    });

//v2.0.0