示例#1
0
        static async Task ReaderText(NatsConnection connection, CancellationToken cancellationToken)
        {
            var history = new Queue <(int count, long time)>();
            var counter = 0;
            var prev    = 0;
            var watch   = Stopwatch.StartNew();

            await foreach (var message in connection.SubscribeText("HELLO", cancellationToken: cancellationToken))
            {
                counter++;
                if (counter % 1_000_000 != 0)
                {
                    continue;
                }
                watch.Stop();
                history.Enqueue((counter - prev, watch.ElapsedMilliseconds));
                prev = counter;
                if (history.Count > 10)
                {
                    history.Dequeue();
                }

                var count = history.Sum(h => h.count);
                var time  = history.Sum(h => h.time);

                Console.WriteLine($"{message} - {count / (double) time * 1000}");
                watch = Stopwatch.StartNew();
            }
        }
示例#2
0
 static async Task ListenerTask(NatsConnection connection, CancellationToken cancellationToken)
 {
     await foreach (var text in connection.SubscribeText("long.message", cancellationToken: cancellationToken))
     {
         Console.WriteLine("Received string {0} characters long", text.Length);
         break;
     }
 }