コード例 #1
0
ファイル: Program.cs プロジェクト: MS-Practice/DotNettyRPC
        static void Main(string[] args)
        {
            RPCServer rPCServer = new RPCServer(39999);

            rPCServer.RegisterService <IBasicDataRpcService, BasicDataRpcService>();
            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: xihu69/DispatchProxyAop
        static void Main(string[] args)
        {
            RPCServer rPCServer = new RPCServer(39999);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.RegisterService <IMail, Mail>();
            rPCServer.Start();

            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            RPCServer rPCServer = new RPCServer(9999);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.RegisterService <IOrderService, OrderService>();
            rPCServer.Start();

            Console.WriteLine(".netCore ecf DotNettyRPC start!");
            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            int port  = 11111;
            int count = 1;

            RPCServer rPCServer = new RPCServer(port);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            Stopwatch watch = new Stopwatch();

            var client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);

            client.SayHello("Hello");

            watch.Start();
            LoopHelper.Loop(count, () =>
            {
                var res = client.SayHello("Hello");
                //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}客户端:{res}");
            });
            watch.Stop();

            Console.WriteLine($"耗时:{(double)watch.ElapsedMilliseconds/count}ms");

            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Action <Exception> handleException = ex =>
            {
                Console.WriteLine(ex.Message);
            };
            int       port      = 9999;
            int       count     = 1000000;
            RPCServer rPCServer = new RPCServer(port);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            IHello    client = null;
            Stopwatch watch  = new Stopwatch();

            watch.Start();
            LoopHelper.Loop(count, () =>
            {
                client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            });
            watch.Stop();

            //var res = client.SayHello("Hello");
            //Console.WriteLine($"客户端:{res}");

            Console.WriteLine($"耗时:{watch.ElapsedMilliseconds}ms");

            Console.ReadLine();
            Console.WriteLine("完成");
            Console.ReadLine();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: lingbohome/EFX.Core
        static void Main(string[] args)
        {
            Console.WriteLine("我是服务端:");
            RPCServer rPCServer = new RPCServer(9999);
            rPCServer.RegisterService<IHello, Hello>();
            rPCServer.Start();

            Console.ReadLine();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: philiahe/Benchmark
        static void Main(string[] args)
        {
            RPCServer rPCServer = new RPCServer(CommonHelper.DotNettyPort);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();

            Console.WriteLine($"RpcServer started on {CommonHelper.DotNettyPort}");
            Console.ReadLine();
        }
コード例 #8
0
        static void DotNettyRPCTest()
        {
            RPCServer rpcServer = new RPCServer(9999);

            rpcServer.RegisterService <IOrderService, OrderService>();
            rpcServer.Start();
            IOrderService client = RPCClientFactory.GetClient <IOrderService>("127.0.0.1", 9999);
            var           res    = client.CalculateFinalOrderSum(9, 3);

            Console.ReadLine();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("启动上传服务");
            //注册编码
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            //注册配置文件
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json");
            var       configuration = builder.Build();
            RPCServer server        = new RPCServer(9999);

            server.RegisterService <IFileUpLoad, FileUpLoad>();
            server.Start();
            Console.ReadLine();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            //WcfTest();
            //SocketTest();
            //DotNettyTest();
            //RpcTest();
            //DotNettyRPCTest();
            RPCServer rpcServer = new RPCServer(9999);

            rpcServer.RegisterService <IHello, Hello>();
            rpcServer.Start();

            Console.WriteLine("完成");
            Console.ReadLine();
        }
コード例 #11
0
        static void RpcTest()
        {
            int       port       = 9999;
            int       count      = 1;
            int       errorCount = 0;
            RPCServer rPCServer  = new RPCServer(port);

            rPCServer.HandleException = ex =>
            {
                Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
            };
            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            IHello client = null;

            client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            client.SayHello("aaa");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            LoopHelper.Loop(1, () =>
            {
                tasks.Add(Task.Run(() =>
                {
                    LoopHelper.Loop(count, () =>
                    {
                        string msg = string.Empty;
                        try
                        {
                            msg = client.SayHello("Hello");
                            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}:{msg}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
                        }
                    });
                }));
            });
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
            Console.WriteLine($"错误次数:{errorCount}");
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: yuyixiaoxiang/DotNettyRPC
        static void DotNettyRPCTest()
        {
            int       threadCount = 1;
            int       port        = 9999;
            int       count       = 10000;
            int       errorCount  = 0;
            RPCServer rPCServer   = new RPCServer(port);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            IHello client = null;

            client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            client.SayHello("aaa");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            for (int i = 0; i < threadCount; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    for (int j = 0; j < count; j++)
                    {
                        string msg = string.Empty;
                        try
                        {
                            //msg = client.SayHello("Hello");
                            //Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}:{msg}");
                        }
                        catch (Exception ex)
                        {
                            errorCount++;
                            //Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
                        }
                    }
                }));
            }
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"并发数:{threadCount},运行:{count}次,每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
            Console.WriteLine($"错误次数:{errorCount}");
        }
コード例 #13
0
        public static void Main(string[] args)
        {
            var host = new HostBuilder()
                       .ConfigureHostConfiguration(configHost =>
            {
                configHost.SetBasePath(Directory.GetCurrentDirectory());
                //configHost.AddJsonFile("hostsettings.json", true, true);
                configHost.AddEnvironmentVariables("ASPNETCORE_");
                //configHost.AddCommandLine(args);
            })
                       .ConfigureAppConfiguration((hostContext, configApp) =>
            {
                configApp.AddJsonFile("appsettings.json", true);
                //configApp.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true);
                configApp.AddEnvironmentVariables();
                //configApp.AddCommandLine(args);
            })
                       .ConfigureServices((hostContext, services) =>
            {
                services.AddLogging();
                //services.AddHostedService<TimedHostedService>();

                services.AddSingleton <IJobFactory, JobFactory>();
                services.AddSingleton <IHello, Hello>();
                services.AddSingleton(provider =>
                {
                    var option = new QuartzOption(hostContext.Configuration);


                    var sf          = new StdSchedulerFactory(option.ToProperties());
                    var scheduler   = sf.GetScheduler().Result;
                    super_scheduler = scheduler;
                    ////3.创建计划
                    //var trigger = TriggerBuilder.Create()
                    //.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever())//每两秒执行一次
                    //.Build();
                    ////4、创建任务
                    //var jobDetail = JobBuilder.Create<TibosJob>()
                    //                .WithIdentity("job", "group4")
                    //                .Build();
                    //scheduler.ScheduleJob(jobDetail, trigger);

                    scheduler.JobFactory = provider.GetService <IJobFactory>();
                    return(scheduler);
                });
                services.AddHostedService <QuartzService>();

                services.AddSingleton <TestJob, TestJob>();
                services.AddSingleton <TibosJob, TibosJob>();


                RPCServer rPCServer = new RPCServer(9988);
                rPCServer.RegisterService <IHello, Hello>();
                rPCServer.Start();
                Console.WriteLine("服务端启动了");
            })
                       .ConfigureLogging((hostContext, configLogging) =>
            {
                configLogging.AddConsole();
                if (hostContext.HostingEnvironment.EnvironmentName == EnvironmentName.Development)
                {
                    configLogging.AddDebug();
                }
            })
                       .UseConsoleLifetime()
                       .Build();

            host.Run();
            Console.ReadLine();
        }