Search in sources :

Example 6 with TopicMessageQuery

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);
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) PublicKey(com.hedera.hashgraph.sdk.PublicKey) TopicId(com.hedera.hashgraph.sdk.TopicId) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery) Given(io.cucumber.java.en.Given)

Example 7 with TopicMessageQuery

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));
}
Also used : Sinks(reactor.core.publisher.Sinks) TopicMessage(com.hedera.hashgraph.sdk.TopicMessage) SubscriptionHandle(com.hedera.hashgraph.sdk.SubscriptionHandle) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery)

Example 8 with TopicMessageQuery

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;
}
Also used : TopicId(com.hedera.hashgraph.sdk.TopicId) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery) Given(io.cucumber.java.en.Given)

Example 9 with TopicMessageQuery

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;
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) TopicId(com.hedera.hashgraph.sdk.TopicId) TopicMessage(com.hedera.hashgraph.sdk.TopicMessage) AbstractScenario(com.hedera.mirror.monitor.AbstractScenario) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery) Status(io.grpc.Status) Instant(java.time.Instant) ScenarioProtocol(com.hedera.mirror.monitor.ScenarioProtocol) Instant(java.time.Instant) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery)

Example 10 with 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);
    });
}
Also used : TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery)

Aggregations

TopicMessageQuery (com.hedera.hashgraph.sdk.TopicMessageQuery)10 TopicId (com.hedera.hashgraph.sdk.TopicId)6 TopicCreateTransaction (com.hedera.hashgraph.sdk.TopicCreateTransaction)4 TopicMessageSubmitTransaction (com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction)4 Given (io.cucumber.java.en.Given)3 Client (com.hedera.hashgraph.sdk.Client)2 TopicDeleteTransaction (com.hedera.hashgraph.sdk.TopicDeleteTransaction)2 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)2 TopicMessage (com.hedera.hashgraph.sdk.TopicMessage)2 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Var (com.google.errorprone.annotations.Var)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 PublicKey (com.hedera.hashgraph.sdk.PublicKey)1 SubscriptionHandle (com.hedera.hashgraph.sdk.SubscriptionHandle)1 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)1 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)1 AbstractScenario (com.hedera.mirror.monitor.AbstractScenario)1 ScenarioProtocol (com.hedera.mirror.monitor.ScenarioProtocol)1