Search in sources :

Example 6 with TopicMessage

use of com.hedera.mirror.common.domain.topic.TopicMessage in project hedera-mirror-node by hashgraph.

the class BatchEntityListenerTest method topicMessage.

protected TopicMessage topicMessage() {
    TopicMessage topicMessage = new TopicMessage();
    topicMessage.setChunkNum(1);
    topicMessage.setChunkTotal(2);
    topicMessage.setConsensusTimestamp(consensusTimestamp++);
    topicMessage.setMessage("test message".getBytes());
    topicMessage.setPayerAccountId(EntityId.of("0.1.1000", EntityType.ACCOUNT));
    topicMessage.setRunningHash("running hash".getBytes());
    topicMessage.setRunningHashVersion(2);
    topicMessage.setSequenceNumber(sequenceNumber++);
    topicMessage.setTopicId(EntityId.of("0.0.101", EntityType.TOPIC));
    topicMessage.setValidStartTimestamp(4L);
    return topicMessage;
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Example 7 with TopicMessage

use of com.hedera.mirror.common.domain.topic.TopicMessage in project hedera-mirror-node by hashgraph.

the class RedisEntityListener method callback.

// Batch send using Redis pipelining
private SessionCallback<Object> callback(List<TopicMessage> messages) {
    return new SessionCallback<>() {

        @Override
        public Object execute(RedisOperations operations) {
            for (TopicMessage topicMessage : messages) {
                String channel = channelNames.get(topicMessage.getTopicId().getId());
                redisOperations.convertAndSend(channel, topicMessage);
            }
            return null;
        }
    };
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) SessionCallback(org.springframework.data.redis.core.SessionCallback)

Example 8 with TopicMessage

use of com.hedera.mirror.common.domain.topic.TopicMessage in project hedera-mirror-node by hashgraph.

the class BatchInserterTest method topicMessage.

private TopicMessage topicMessage(long consensusNs, int messageSize) {
    TopicMessage topicMessage = new TopicMessage();
    topicMessage.setConsensusTimestamp(consensusNs);
    topicMessage.setPayerAccountId(EntityId.of("0.0.1002", ACCOUNT));
    // Just exceeds 8000B
    topicMessage.setMessage(RandomUtils.nextBytes(messageSize));
    topicMessage.setRunningHash(Strings.toByteArray("running hash"));
    topicMessage.setRunningHashVersion(2);
    topicMessage.setSequenceNumber(consensusNs);
    topicMessage.setTopicId(EntityId.of("0.0.1001", EntityType.TOPIC));
    return topicMessage;
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Example 9 with TopicMessage

use of com.hedera.mirror.common.domain.topic.TopicMessage in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertConsensusTopicMessage.

private void insertConsensusTopicMessage(RecordItem recordItem) {
    if (!entityProperties.getPersist().isTopics()) {
        return;
    }
    ConsensusSubmitMessageTransactionBody transactionBody = recordItem.getTransactionBody().getConsensusSubmitMessage();
    TransactionRecord transactionRecord = recordItem.getRecord();
    var receipt = transactionRecord.getReceipt();
    var topicId = transactionBody.getTopicID();
    int runningHashVersion = receipt.getTopicRunningHashVersion() == 0 ? 1 : (int) receipt.getTopicRunningHashVersion();
    TopicMessage topicMessage = new TopicMessage();
    // Handle optional fragmented topic message
    if (transactionBody.hasChunkInfo()) {
        ConsensusMessageChunkInfo chunkInfo = transactionBody.getChunkInfo();
        topicMessage.setChunkNum(chunkInfo.getNumber());
        topicMessage.setChunkTotal(chunkInfo.getTotal());
        if (chunkInfo.hasInitialTransactionID()) {
            topicMessage.setInitialTransactionId(chunkInfo.getInitialTransactionID().toByteArray());
        }
    }
    topicMessage.setConsensusTimestamp(DomainUtils.timeStampInNanos(transactionRecord.getConsensusTimestamp()));
    topicMessage.setMessage(DomainUtils.toBytes(transactionBody.getMessage()));
    topicMessage.setPayerAccountId(recordItem.getPayerAccountId());
    topicMessage.setRunningHash(DomainUtils.toBytes(receipt.getTopicRunningHash()));
    topicMessage.setRunningHashVersion(runningHashVersion);
    topicMessage.setSequenceNumber(receipt.getTopicSequenceNumber());
    topicMessage.setTopicId(EntityId.of(topicId));
    entityListener.onTopicMessage(topicMessage);
}
Also used : ConsensusMessageChunkInfo(com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 10 with TopicMessage

use of com.hedera.mirror.common.domain.topic.TopicMessage in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method getTopicMessage.

private TopicMessage getTopicMessage() {
    TopicMessage topicMessage = new TopicMessage();
    topicMessage.setChunkNum(1);
    topicMessage.setChunkTotal(2);
    topicMessage.setConsensusTimestamp(1L);
    topicMessage.setMessage("test message".getBytes());
    topicMessage.setPayerAccountId(EntityId.of("0.1.1000", EntityType.ACCOUNT));
    topicMessage.setRunningHash("running hash".getBytes());
    topicMessage.setRunningHashVersion(2);
    topicMessage.setSequenceNumber(1L);
    topicMessage.setTopicId(EntityId.of("0.0.1001", EntityType.TOPIC));
    topicMessage.setValidStartTimestamp(4L);
    return topicMessage;
}
Also used : TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Aggregations

TopicMessage (com.hedera.mirror.common.domain.topic.TopicMessage)14 Test (org.junit.jupiter.api.Test)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 BatchEntityListenerTest (com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest)2 RedisOperations (org.springframework.data.redis.core.RedisOperations)2 SessionCallback (org.springframework.data.redis.core.SessionCallback)2 StreamMessage (com.hedera.mirror.common.domain.topic.StreamMessage)1 EntityBatchCleanupEvent (com.hedera.mirror.importer.parser.record.entity.EntityBatchCleanupEvent)1 EntityBatchSaveEvent (com.hedera.mirror.importer.parser.record.entity.EntityBatchSaveEvent)1 ConsensusMessageChunkInfo (com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo)1 ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)1 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)1 ArrayList (java.util.ArrayList)1 TestInstance (org.junit.jupiter.api.TestInstance)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 PGNotification (org.postgresql.PGNotification)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 RedisCallback (org.springframework.data.redis.core.RedisCallback)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 RedisSerializer (org.springframework.data.redis.serializer.RedisSerializer)1