Ejemplo n.º 1
0
        public static void MeropsRegistryClientTest()
        {
            try
            {
                RpcInitializer.Initialize();

                var client = ClientFactory.GetInstance <IRegistryService>("http://localhost:12974/api/service/");

                var resp = client.GetServiceInfoAsync(new GetServiceInfoRequest
                {
                    Services = new[]
                    {
                        new ServiceIdentifierDto
                        {
                            Name  = "ProductService",
                            Group = "IT",
                        }
                    }
                });

                Console.WriteLine(resp.Result.Services.First().ServiceInfos.First().Address.ToString());
            }
            catch (ConnectionException ex)
            {
                Console.WriteLine(ex);
                //throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //throw;
            }
        }
Ejemplo n.º 2
0
        private static void TestHttpClient()
        {
            try
            {
                var address = serviceBaseUrl + @"/api/service/";
#if NETCORE
                var config = new RpcConfigBuilder()
                             .UseClient <IProductService>("ProductService")
                             .Build();

                RpcInitializer.Initialize(config);
#else
                RpcInitializer.Initialize();
#endif
                var client     = ClientFactory.GetInstance <IProductService>(address);
                var clientInfo = (IRpcClient)client;
                //clientInfo.Formatter = new XmlFormatter();
                clientInfo.Format = "xml";

                TestService(client).Wait();
                TpsTest(client);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 3
0
        private static void PerformanceTest()
        {
            RpcInitializer.Initialize();

            var client = ClientFactory.GetInstance <IProductService>(serviceBaseUrl + "/api/service/");

            try
            {
                var clientInfo = client as IRpcClient;
                Console.WriteLine(clientInfo.Address);
                Console.WriteLine(clientInfo.Formatter.ToString());

                var v01 = client.GetAll();

                var times = 5;

                Console.WriteLine("get 1 products");
                for (int idxTime = 0; idxTime < times; idxTime++)
                {
                    using (new TimeRecorder())
                    {
                        var v1 = client.GetPage(1, 1);
                    }
                }

                Console.WriteLine("get 10 products");
                for (int idxTime = 0; idxTime < times; idxTime++)
                {
                    using (new TimeRecorder())
                    {
                        var v1 = client.GetAll();
                    }
                }

                Console.WriteLine("get 100 products");
                for (int idxTime = 0; idxTime < times; idxTime++)
                {
                    using (new TimeRecorder())
                    {
                        var v1 = client.GetPage(1, 100);
                    }
                }

                Console.WriteLine("get 1000 products");
                for (int idxTime = 0; idxTime < times; idxTime++)
                {
                    using (new TimeRecorder())
                    {
                        var v1 = client.GetPage(1, 1000);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            //Console.Write(nameof(PerformanceTest) + "finish, press enter to exit");
            //Console.ReadLine();
        }
Ejemplo n.º 4
0
 protected void Application_Start(object sender, EventArgs e)
 {
     RpcInitializer.Initialize(builder => builder
                               .UseService <ProductService>("ProductService", "api/service/")
                               .UseService <TestService>("ProductService", "api/test/")
                               .UseServicePaths("api/")
                               );
 }
Ejemplo n.º 5
0
        static async Task Main()
        {
            Console.Title = "Сервер";
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;

            RpcInitializer.Initialize(_memoryManager);
            using (var listener = new VRpcListener(IPAddress.Any, Port))
            {
                listener.ConfigureService(ioc =>
                {
                    ioc.AddLogging(loggingBuilder =>
                    {
                        loggingBuilder
                        .AddConsole()
                        .AddDebug();
                    });

                    ioc.AddSingleton(new Program());
                });

                Console.CancelKeyPress += (_, e) =>
                {
                    e.Cancel = true;
                    lock (_conLock)
                    {
                        Console.WriteLine("Stopping...");
                    }
                    listener.BeginShutdown(TimeSpan.FromSeconds(3), "Пользователь нажал Ctrl+C");
                };

                listener.ClientConnected    += Listener_ClientConnected;
                listener.ClientDisconnected += Listener_ClientDisconnected;

                //var lt = listener.ServiceProvider.GetRequiredService<IHostApplicationLifetime>();

                await listener.RunAsync();

                //listener.Start();

                //Console.Clear();
                //long prev = 0;
                //var sw = Stopwatch.StartNew();
                //while (!listener.Completion.IsCompleted)
                //{
                //    Thread.Sleep(1000);
                //    long elapsedMs = sw.ElapsedMilliseconds;
                //    long rCount = Interlocked.Read(ref ReqCount);
                //    ulong reqPerSecond = unchecked((ulong)(rCount - prev));
                //    prev = rCount;
                //    sw.Restart();

                //    var reqPerSec = (int)Math.Round(reqPerSecond * 1000d / elapsedMs);
                //    ToConsole(Interlocked.Read(ref _connections), reqPerSec, ReqCount);
                //}
                //ToConsole(0, 0, 0);
            }
        }
Ejemplo n.º 6
0
        private static void ClientTest1()
        {
            //var baseUrl = @"http://*****:*****@"https://www.baidu.com/test/api/service/";
            //var baseUrl = @"http://localhost/config/asfsdfs";

            RpcInitializer.Initialize();

            var address    = serviceBaseUrl + @"/api/service/";
            var client     = ClientFactory.GetInstance <IProductService>(address);
            var clientInfo = (IRpcClient)client;

            clientInfo.Formatter = new XmlFormatter();


            //var client = ClientFactory.GetInstance<IProductService>();

            try
            {
                client.ExceptionTest();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            //return;

            try
            {
                var products  = client.GetAll();
                var products2 = client.GetAllAsync().Result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            try
            {
                client.ExceptionTestAsync().Wait();
            }
            catch (AggregateException ex)
            {
                Console.WriteLine(ex.InnerException);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Client Test Finish");
        }
Ejemplo n.º 7
0
 private static void InitializeTest()
 {
     RpcInitializer.Initialize(builder => builder
                               .UseAppId("10000")
                               .UseClient <IProductService>("ProductService"));
 }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public void Init(HttpApplication context)
 {
     RpcInitializer.Initialize();
     context.PostResolveRequestCache += Context_PostResolveRequestCache;
 }
Ejemplo n.º 9
0
 static RpcAsyncHandler()
 {
     RpcInitializer.Initialize();
 }