Example #1
0
 public GrpcWorkerClient(LoggingContext loggingContext, DistributedInvocationId invocationId, string ipAddress, int port, EventHandler <ConnectionFailureEventArgs> onConnectionFailureAsync)
 {
     m_loggingContext    = loggingContext;
     m_connectionManager = new ClientConnectionManager(loggingContext, ipAddress, port, invocationId);
     m_connectionManager.OnConnectionFailureAsync += onConnectionFailureAsync;
     m_client = new Worker.WorkerClient(m_connectionManager.Channel);
 }
Example #2
0
 public GrpcWorkerClient(LoggingContext loggingContext, string buildId, string ipAddress, int port, EventHandler <ConnectionTimeoutEventArgs> onConnectionTimeOutAsync)
 {
     m_loggingContext    = loggingContext;
     m_connectionManager = new ClientConnectionManager(loggingContext, ipAddress, port, buildId);
     m_connectionManager.OnConnectionTimeOutAsync += onConnectionTimeOutAsync;
     m_client = new Worker.WorkerClient(m_connectionManager.Channel);
 }
Example #3
0
 public GrpcWorkerClient(LoggingContext loggingContext, string buildId, string ipAddress, int port, EventHandler onConnectionTimeOutAsync, Func <CancellationToken, Task <IDisposable> > attachAcquireAsync)
 {
     m_loggingContext    = loggingContext;
     m_connectionManager = new ClientConnectionManager(loggingContext, ipAddress, port, buildId);
     m_connectionManager.OnConnectionTimeOutAsync += onConnectionTimeOutAsync;
     m_client             = new Worker.WorkerClient(m_connectionManager.Channel);
     m_attachAcquireAsync = attachAcquireAsync;
 }
Example #4
0
 public GrpcWorkerClient(LoggingContext loggingContext, string buildId, string ipAddress, int port)
 {
     m_loggingContext    = loggingContext;
     m_connectionManager = new ClientConnectionManager(loggingContext, ipAddress, port, buildId);
     m_client            = new Worker.WorkerClient(m_connectionManager.Channel);
     m_senderInfo        = new SenderInfo()
     {
         BuildId    = buildId,
         SenderName = MachineName,
         SenderId   = Guid.NewGuid().ToString()
     };
 }
Example #5
0
        static async Task Main(string[] args)
        {
            var channel = new Channel("localhost:5010", ChannelCredentials.Insecure);
            var client  = new Worker.WorkerClient(channel);

            var reply = await client.SayHelloAsync(
                new HelloRequest
            {
                Name = "GreeterClient"
            });

            Console.WriteLine("Greeting: " + reply.Message);

            var randomStream = client.Random(
                new RandomRequest
            {
                Count    = 10,
                MinValue = 100,
                MaxValue = 200
            }).ResponseStream;

            var ct = _cancellationTokenSource.Token;

            while (await randomStream.MoveNext(ct))
            {
                Console.WriteLine($"Random number: {randomStream.Current.Value}");
            }

            using (var addClient = client.Add())
            {
                while (true)
                {
                    Console.Write("Enter number (0 to exit): ");
                    var value = int.Parse(Console.ReadLine());
                    if (value == 0)
                    {
                        break;
                    }

                    await addClient.RequestStream.WriteAsync(new AddRequest { Value = value });
                }
                await addClient.RequestStream.CompleteAsync();

                var response = await addClient.ResponseAsync;
                Console.WriteLine($"Total: {response.Value}");
            }

            await channel.ShutdownAsync();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Example #6
0
        public async Task Run()
        {
            await Task.Yield();

            var sw = new Stopwatch();

            sw.Start();
            do
            {
                await Task.Delay(100);

                ThreadPool.QueueUserWorkItem(async _ =>
                {
                    ThreadPool.GetAvailableThreads(out var availableThreads, out var _);
                    _stats.Gauge(availableThreads, "GaugeAvailableThreads");

                    _stats.Increment("CountRequests");
                    await _stats.Time("TimeWait", async f => await _semaphoreSlim.WaitAsync());

                    try
                    {
                        var parameter     = new Random(DateTime.Now.Millisecond).Next(20);
                        using var channel = GrpcChannel.ForAddress(_settings.WorkerServiceEndpoint);
                        var client        = new Worker.WorkerClient(channel);
                        var reply         = await client.FactorialAsync(new FactorialRequest {
                            Factor = parameter
                        });
                        _stats.Increment("CountProcessed");
                    }
                    finally
                    {
                        _semaphoreSlim.Release();
                    }
                });
            } while (_settings.LoadSecondsInterval == 0 || (sw.ElapsedMilliseconds <= _settings.LoadSecondsInterval * 1000));
            sw.Stop();
        }
Example #7
0
 public GrpcWorkerClient(LoggingContext loggingContext, string buildId, string ipAddress, int port)
 {
     m_loggingContext    = loggingContext;
     m_connectionManager = new ClientConnectionManager(loggingContext, ipAddress, port, buildId);
     m_client            = new Worker.WorkerClient(m_connectionManager.Channel);
 }