Exemplo n.º 1
0
        public override async Task RunAsync()
        {
            var pool = new EventHubClientPool(() => CreateEventHubClient());

            try
            {
                int count   = 0;
                var elapsed = await TimeFunctionAsync(async() =>
                {
                    var cancellationTokenSource = new CancellationTokenSource(_samplingTime);
                    var threads = (from i in Enumerable.Range(0, _threadCount)
                                   select OneThreadAsync(pool, cancellationTokenSource.Token)).ToArray();

                    await Task.WhenAll(threads);

                    var counts = from t in threads
                                 select t.Result;

                    count = counts.Sum();
                });

                Console.WriteLine($"Total Events:  {count}");
                Console.WriteLine($"Duration:  {elapsed}");
                Console.WriteLine($"Throughput:  {(double)count / elapsed.TotalSeconds}");
                Console.WriteLine($"Connection Pool size:  {pool.PoolSize}");
            }
            finally
            {
                await pool.CloseAsync();
            }
        }
        async Task IEventHubClient.CloseAsync()
        {
            //  Ensure queue processing is initiated immediatly
            await ProcessBatchAsync();

            await _clientPool.CloseAsync();
        }