use of com.hedera.hashgraph.sdk.TopicMessage 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.TopicMessage in project hedera-mirror-node by hashgraph.
the class SubscriptionResponse method validateReceivedMessages.
public void validateReceivedMessages() throws Exception {
int invalidMessages = 0;
TopicMessage lastTopicMessage = null;
for (MirrorHCSResponse mirrorHCSResponseResponse : mirrorHCSResponses) {
TopicMessage topicMessage = mirrorHCSResponseResponse.getTopicMessage();
Instant publishInstant = Instant.ofEpochMilli(Longs.fromByteArray(topicMessage.contents));
long publishSeconds = publishInstant.getEpochSecond();
long consensusSeconds = topicMessage.consensusTimestamp.getEpochSecond();
long receiptSeconds = mirrorHCSResponseResponse.getReceivedInstant().getEpochSecond();
long e2eSeconds = receiptSeconds - publishSeconds;
long consensusToDelivery = receiptSeconds - consensusSeconds;
log.trace("Observed message, e2eSeconds: {}s, consensusToDelivery: {}s, publish timestamp: {}, " + "consensus timestamp: {}, receipt time: {}, topic sequence number: {}", e2eSeconds, consensusToDelivery, publishInstant, topicMessage.consensusTimestamp, mirrorHCSResponseResponse.getReceivedInstant(), topicMessage.sequenceNumber);
if (!validateResponse(lastTopicMessage, topicMessage)) {
invalidMessages++;
}
lastTopicMessage = topicMessage;
}
if (invalidMessages > 0) {
throw new Exception("Retrieved {} invalid messages in response");
}
log.info("{} messages were successfully validated", mirrorHCSResponses.size());
}
Aggregations