Show / Hide Table of Contents

Class SubscribeTopicParams

Parameters for subscribing to a consensus topic message stream from a mirror node.

Inheritance
object
SubscribeTopicParams
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public sealed class SubscribeTopicParams
Examples

Stream messages from the current time forward into a Channel<TopicMessage>. The subscription runs in the background; the consumer reads from the channel:

await using var stream = new MirrorGrpcClient(ctx =>
{
    ctx.Uri = new Uri(mirrorEndpoint);
});

var channel = Channel.CreateUnbounded<TopicMessage>();
var topic = new EntityId(0, 0, topicNum);

Console.WriteLine($"Subscribing to topic 0.0.{topicNum}...");
Console.WriteLine("Waiting for messages (Ctrl+C to stop)...");

// Start subscription in the background. Messages arrive via channel.Writer
// so this task runs independently of the consumer loop below.
var subscribeTask = stream.SubscribeTopicAsync(new SubscribeTopicParams
{
    Topic = topic,
    MessageWriter = channel.Writer,
    Starting = ConsensusTimeStamp.MinValue,
    MaxCount = maxMessages,
    CancellationToken = cts.Token
});

// Read messages as they arrive
try
{
    await foreach (var msg in channel.Reader.ReadAllAsync(cts.Token))
    {
        var text = Encoding.UTF8.GetString(msg.Message.Span);
        Console.WriteLine($"[Seq {msg.SequenceNumber}] {msg.Consensus}: {text}");
    }
}
catch (OperationCanceledException)
{
    Console.WriteLine("Subscription cancelled.");
}

await subscribeTask;

Properties

| Edit this page View Source

CancellationToken

Optional cancellation token, that when set, closes the mirror node connection and optionally the .net channel (if configured to do so), and causes the SubscribeTopic method to return without error. Default is "none", the method can be completed by signaling the receiving .net channel as completed.

Declaration
public CancellationToken CancellationToken { get; set; }
Property Value
Type Description
CancellationToken
| Edit this page View Source

CompleteChannelWhenFinished

Indicate that the .net channel should be "completed" when the streaming connection to the mirror node completes, both for planned and faulted reasons. Default is true. Set to false to re-use the channel or for scenarios where it may be combined and multiplexed with other channel combinations.

Declaration
public bool CompleteChannelWhenFinished { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

Ending

Optional, filter for messages which reached consensus before this time. If not set, it will stream indefinitely.

Declaration
public ConsensusTimeStamp? Ending { get; set; }
Property Value
Type Description
ConsensusTimeStamp?
| Edit this page View Source

MaxCount

Optional, the maximum number of topic messages to return before completing the call, if set to 0 it will stream messages indefinitely until the stream terminates by other means.

Declaration
public ulong MaxCount { get; set; }
Property Value
Type Description
ulong
| Edit this page View Source

MessageWriter

.NET system threading channel writer receiving messages streamed from the server. Messages can be read from the stream by calling code without blocking the incoming stream of messages from the mirror node. Completing the stream will close the streaming connection to the mirror node and cause this method to return without error.

Declaration
public ChannelWriter<TopicMessage> MessageWriter { get; set; }
Property Value
Type Description
ChannelWriter<TopicMessage>
| Edit this page View Source

Starting

Optional, filter for messages which reached consensus on or after this time. If not set, messages occurring from the current time forward are returned.

Declaration
public ConsensusTimeStamp? Starting { get; set; }
Property Value
Type Description
ConsensusTimeStamp?
| Edit this page View Source

Topic

The topic to subscribe to.

Declaration
public EntityId Topic { get; set; }
Property Value
Type Description
EntityId
  • Edit this page
  • View Source
In this article
Back to top .NET Client Library for Hiero Network and Hedera Hashgraph