use of com.hedera.hashgraph.sdk.TopicMessageQuery in project hedera-mirror-node by hashgraph.
the class TopicFeature method createNewTopic.
@Given("I successfully create a new topic id")
public void createNewTopic() {
testInstantReference = Instant.now();
submitKey = PrivateKey.generate();
PublicKey submitPublicKey = submitKey.getPublicKey();
log.trace("Topic creation PrivateKey : {}, PublicKey : {}", submitKey, submitPublicKey);
NetworkTransactionResponse networkTransactionResponse = topicClient.createTopic(topicClient.getSdkClient().getExpandedOperatorAccountId(), submitPublicKey);
assertNotNull(networkTransactionResponse.getReceipt());
TopicId topicId = networkTransactionResponse.getReceipt().topicId;
assertNotNull(topicId);
consensusTopicId = topicId;
topicMessageQuery = new TopicMessageQuery().setTopicId(consensusTopicId).setStartTime(Instant.EPOCH);
log.debug("Set TopicMessageQuery with topic: {}, startTime: {}", consensusTopicId, Instant.EPOCH);
}
use of com.hedera.hashgraph.sdk.TopicMessageQuery in project hedera-mirror-node by hashgraph.
the class GrpcClientSDK method subscribeToClient.
private Flux<SubscribeResponse> subscribeToClient(Client client, GrpcSubscription subscription) {
Sinks.Many<TopicMessage> sink = Sinks.many().multicast().directBestEffort();
TopicMessageQuery topicMessageQuery = subscription.getTopicMessageQuery();
topicMessageQuery.setCompletionHandler(sink::tryEmitComplete);
topicMessageQuery.setErrorHandler((throwable, topicMessage) -> sink.tryEmitError(throwable));
// Disable since we use our own retry logic to capture errors
topicMessageQuery.setMaxAttempts(0);
SubscriptionHandle subscriptionHandle = topicMessageQuery.subscribe(client, sink::tryEmitNext);
return sink.asFlux().publishOn(Schedulers.parallel()).doFinally(s -> subscriptionHandle.unsubscribe()).doOnComplete(subscription::onComplete).doOnError(subscription::onError).doOnNext(subscription::onNext).map(t -> toResponse(subscription, t));
}
use of com.hedera.hashgraph.sdk.TopicMessageQuery in project hedera-mirror-node by hashgraph.
the class TopicFeature method setTopicIdParam.
@Given("I provide a topic id {string}")
public void setTopicIdParam(String topicId) {
testInstantReference = Instant.now();
topicMessageQuery = new TopicMessageQuery().setStartTime(Instant.EPOCH);
consensusTopicId = null;
if (!topicId.isEmpty()) {
consensusTopicId = new TopicId(0, 0, Long.parseLong(topicId));
topicMessageQuery.setTopicId(consensusTopicId);
}
log.debug("Set TopicMessageQuery with topic: {}, StartTime: {}", consensusTopicId, Instant.EPOCH);
messageSubscribeCount = 0;
}
use of com.hedera.hashgraph.sdk.TopicMessageQuery in project hedera-mirror-node by hashgraph.
the class GrpcSubscription method getTopicMessageQuery.
TopicMessageQuery getTopicMessageQuery() {
long limit = properties.getLimit();
Instant startTime = getLast().map(t -> t.consensusTimestamp.plusNanos(1)).orElseGet(properties::getStartTime);
TopicMessageQuery topicMessageQuery = new TopicMessageQuery();
topicMessageQuery.setEndTime(properties.getEndTime());
topicMessageQuery.setLimit(limit > 0 ? limit - counter.get() : 0);
topicMessageQuery.setStartTime(startTime);
topicMessageQuery.setTopicId(TopicId.fromString(properties.getTopicId()));
return topicMessageQuery;
}
use of com.hedera.hashgraph.sdk.TopicMessageQuery in project hedera-sdk-java by hashgraph.
the class ConsensusPubSubWithSubmitKeyExample method subscribeToTopic.
/**
* Subscribe to messages on the topic, printing out the received message and metadata as it is published by the
* Hedera mirror node.
*/
private void subscribeToTopic() {
new TopicMessageQuery().setTopicId(topicId).setStartTime(Instant.ofEpochSecond(0)).subscribe(client, (resp) -> {
String messageAsString = new String(resp.contents, StandardCharsets.UTF_8);
System.out.println(resp.consensusTimestamp + " received topic message: " + messageAsString);
});
}
Aggregations