Esempio n. 1
0
        private static PersonDto PersonHandler(PersonKeyDto request, CancellationToken cancellationToken)
        {
            PersonDto response;

            Console.WriteLine($"Request Person {++_requestPersonCount} : " + request.SerializeToJson());

            switch (request.Id)
            {
            case 1:
                response = new PersonDto {
                    Id = request.Id, Name = "Monique", BirthDate = new DateTime(1975, 10, 5)
                };
                break;

            case 2:
                response = new PersonDto {
                    Id = request.Id, Name = "Cathrine", BirthDate = new DateTime(2007, 6, 6)
                };
                break;

            default:
                response = null;
                break;
            }

            Console.WriteLine("Response Person: " + response.SerializeToJson());

            return(response);
        }
Esempio n. 2
0
        private void RequestPerson(ref string input)
        {
            var request = new PersonKeyDto();

            int.TryParse(input, out request.Id);

            Request <PersonKeyDto, PersonDto>(SampleApiConfiguration.Person, request);

            input = "";
        }
Esempio n. 3
0
        private void RequestAsyncMulti(ref string inputString)
        {
            Console.WriteLine();

            var request = new PersonKeyDto {
                Id = 1
            };

            int.TryParse(inputString, out var count);

            Console.WriteLine($"Requesting Async {count} times");

            try
            {
                var stopwatch = new Stopwatch();
                var responses = new List <Task <PersonDto> >();

                stopwatch.Start();

                for (var i = 0; i < count; ++i)
                {
                    responses.Add(_messageBus.RequestAsync <PersonKeyDto, PersonDto>(SampleApiConfiguration.Person, request));
                }

                Console.WriteLine($"RequestAsync Done - Count: {count} - Total: {(double)stopwatch.ElapsedMilliseconds / 1000:#0.###}s - Average: {stopwatch.ElapsedMilliseconds / count}ms");

                foreach (var response in responses)
                {
                    if (response == null)
                    {
                        throw new NullReferenceException("Missing request reply");
                    }

                    if (response.Result == null)
                    {
                        throw new NullReferenceException("Missing request reply");
                    }
                }

                stopwatch.Stop();

                Console.WriteLine($"Response from all - Count: {count} - Total: {(double)stopwatch.ElapsedMilliseconds / 1000:#0.###}s - Average: {stopwatch.ElapsedMilliseconds / count}ms");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception requesting: " + exception.SerializeToJson());
            }

            inputString = "";
        }