/// <summary> /// /// </summary> /// <param name="config"></param> public static void Initialize(RpcConfig config) { if (AppHost != null) { return; //throw new InvalidOperationException("default service host already initialized"); } lock (InitilizeLock) { if (AppHost == null) { AppHost = new AppHost(config); AppHost.Initialize(); } } }
public static void DefaultRegistryTest() { var config = new RpcConfigBuilder() .UseClient<IProductService>("ProductService", "http://localhost:5000/api/service/") .UseClient<IServiceTestService1>("IServiceTestService1", "http://localhost:5000/api/service/") .UseClient<IServiceTestService2>("IServiceTestService2", "it1", "http://localhost:5000/api/service/") .Build(); var appHost = new AppHost(config); var si1 = appHost.Registry.LookupAsync<IProductService>().Result; var si2 = appHost.Registry.LookupAsync("ProductService").Result; var si3 = appHost.Registry.LookupAsync("ProductService2").Result; var si4 = appHost.Registry.LookupAsync<IServiceTestService2>().Result; var si5 = appHost.Registry.LookupAsync("IServiceTestService2").Result; var si6 = appHost.Registry.LookupAsync("IServiceTestService2", "it1").Result; var si7 = appHost.Registry.LookupAsync("IServiceTestService2", "it2").Result; }
public static void Test1() { Console.WriteLine("start test"); //Console.ReadLine(); var config = new ConfigurationBuilder() .AddJsonFile("rpclite.config.json") .Build(); var appHost = new AppHost(config); appHost.Initialize(); var client = appHost.ClientFactory.GetInstance<IProductService>(); var channel = new MemoryClientChannel(appHost) { Address = "/api/service/" }; ((IRpcClient<IProductService>)client).Invoker = new MemoryInvoker(appHost, "/api/service/"); //((IRpcClient)client).Channel = channel; var products = client.GetAll(); while (true) { Console.WriteLine("press enter to start 10000 test"); Console.ReadLine(); var stopwatch = Stopwatch.StartNew(); var times = 10000; for (int i = 0; i < times; i++) { var products2 = client.GetAll(); } stopwatch.Stop(); Console.WriteLine($"Elapsed: {stopwatch.Elapsed.TotalMilliseconds}, {times * 1000 / stopwatch.Elapsed.TotalMilliseconds} tps"); } Console.ReadLine(); }
public static void Test2() { #region prepare config //var config = new RpcLiteConfig //{ // AppId = "10000", // Registry = new RegistryConfigItem("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/"), // //Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(MeropsMonitorFactory), "http://localhost:6201/api/service/"), // Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/"), // Services = new List<ServiceConfigItem> // { // new ServiceConfigItem("ProductService", typeof(ProductService), "/service/"), // }, // Clients = new List<ClientConfigItem> // { // new ClientConfigItem("ProductService", typeof(IProductService), "/service/"), // } //}; //var appHost = new AppHost(config); //var appHost = new AppHostBuilder() // .UseAppId("10000") // .UseRegistry("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/") // .UseMonitor("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/") // .UseServices(new ServiceConfigItem("ProductService", typeof(ProductService), "/service/")) // .UseClients(new ClientConfigItem("ProductService", typeof(IProductService), "/service/")) // .Build(); #endregion ////var config1 = new ConfigurationBuilder() //// .AddJsonFile("rpclite.config.json") //// .Build(); ////var config2 = RpcConfigHelper.GetConfig(new CoreConfiguration(config1)); var config = new RpcConfigBuilder() .UseAppId("10000") .UseRegistry<MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor<ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") .UseInvoker<DefaultInvokerFactory>(null) .UseFilter<UnitTestFilterFactory>() .Build(); var appHost2 = new AppHost(config); var path = "/service/"; var appHost = new AppHostBuilder() .UseAppId("10000") .UseRegistry<MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor<ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") //.UseServiceMapper<DefaultServiceMapperFactory>("DefaultServiceMapper") .UseService<ProductService>("ProductService", path, null) .UseInvoker<DefaultInvokerFactory>(null) //.UseClient<IProductService>("ProductService", "/service/") .UseFilter<UnitTestFilterFactory>() .Build(); appHost.Initialize(); //appHost.AddFilter(new LogTimeFilter()); //appHost.AddFilter(new LogRequestTimeFilter()); //appHost.AddFilter(new EmptyFilter()); //appHost.AddFilter(new EmptyFilter()); var client = appHost.ClientFactory.GetInstance<IProductService>(); var clientInfo = (IRpcClient<IProductService>)client; clientInfo.Invoker = new MemoryInvoker(appHost, path); clientInfo.Formatter = new XmlFormatter(); clientInfo.Format = "xml"; Console.WriteLine("start test"); try { var id1 = client.Add(new Product { Id = 1, }); Assert.AreEqual(id1, 1); client.Add(null); } catch (Exception ex) { Console.WriteLine(ex); } var exObj = new PlatformNotSupportedException("win31"); try { client.ThrowException(exObj); } catch (Exception ex) { //Assert.AreEqual(ex.GetType(), exObj.GetType()); //Assert.AreEqual(ex.Message, exObj.Message); } var ps = client.GetByIdAsync(1).Result; Assert.AreEqual(ps.Id, 1); var products = client.GetAll(); while (true) { var times = 1000; Console.WriteLine(); Console.Write($"press enter to start {times} test"); Console.ReadLine(); Console.WriteLine("testing..."); var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { //var products2 = client.GetPage(1, 1000); var products22 = client.GetPage(1, 1); //var products3 = client.GetCount(); } stopwatch.Stop(); Console.WriteLine($"Elapsed: {stopwatch.Elapsed.TotalMilliseconds}, {times * 1000 / stopwatch.Elapsed.TotalMilliseconds} tps, {stopwatch.Elapsed.TotalMilliseconds / times}ms/t"); } Console.ReadLine(); }
public static void MeropsRegistryTest() { var config = new RpcConfigBuilder() .UseClient<IProductService>("ProductService", "IT", null) .UseClient<IServiceTestService1>("IServiceTestService1", "http://localhost:5000/api/service/") .UseClient<IServiceTestService2>("IServiceTestService2", "it1", "http://localhost:5000/api/service/") .UseRegistry<MeropsRegistryFactory>(null, "http://localhost:12974/api/service/") .Build(); var appHost = new AppHost(config); var client = appHost.ClientFactory.GetInstance<IProductService>(); var clientInfo = (IRpcClient)client; var serviceAddress = clientInfo.Address; Console.ReadLine(); }