예제 #1
0
        public async Task <InputDto> RemoteCallTest(InputDto input)
        {
            var helloService      = serviceProxyFactory.CreateProxy <IHelloService>();
            var helloactorService = serviceProxyFactory.CreateActorProxy <IHelloActorService>();
            await stateManager.SetState(new TestStateDto("mykey", true));

            var getState = await stateManager.GetState <bool>(new TestStateDto("mykey"));

            var delState = await stateManager.DelState(new TestStateDto("mykey"));

            var invokeresult = await helloService.GetUserInfo(new InputDto()
            {
                name = "xiaoming"
            });

            var invokenoinputresult = await helloService.Test();

            var eventresult = await eventBus.SendEvent("test", new TestEventDto()
            {
                myword = "abc"
            });

            var actorresult = await helloactorService.GetUserInfoByActor(new ActorInputDto()
            {
                Name = "xiaoming", ActorId = "1"
            });

            return(new InputDto()
            {
                name = $"RPC无参调用成功,回调:{JsonSerializer.Serialize(invokenoinputresult)},RPC有参调用成功,回调:{JsonSerializer.Serialize(invokeresult)},事件发送{(eventresult != null ? "成功" : "失败")},状态写入成功,值:{getState},actor调用成功,回调:{JsonSerializer.Serialize(actorresult)}"
            });
        }
예제 #2
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUser(new UserModel {
             UserId = 1
         });
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 await userProxy.GetUser(new UserModel {
                     UserId = 1
                 });
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.ReadLine();
         } while (true);
     }).Wait();
 }
예제 #3
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUserId("user");
         var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 var a = userProxy.GetUser(new IModuleServices.Common.Models.UserModel()
                 {
                     Name = "fanly"
                 }).Result;
                 //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.WriteLine("Press any key to continue, q to exit the loop...");
             var key = Console.ReadLine();
             if (key.ToLower() == "q")
             {
                 break;
             }
         } while (true);
     }).Wait();
 }
예제 #4
0
        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="serviceProxyFactory"></param>
        public static void Test(IServiceProxyFactory serviceProxyFactory)
        {
            var tracingContext = ServiceLocator.GetService <ITracingContext>();

            Task.Run(async() =>
            {
                RpcContext.GetContext().SetAttachment("xid", 124);

                var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
                var user      = userProxy.GetUser(new UserModel {
                    UserId = 1,
                    Name   = "fanly",
                    Age    = 120,
                    Sex    = 0
                }).GetAwaiter().GetResult();
                var e  = userProxy.SetSex(Sex.Woman).GetAwaiter().GetResult();
                var v  = userProxy.GetUserId("fanly").GetAwaiter().GetResult();
                var fa = userProxy.GetUserName(1).GetAwaiter().GetResult();
                userProxy.Try().GetAwaiter().GetResult();
                var v1        = userProxy.GetUserLastSignInTime(1).Result;
                var things    = userProxy.GetAllThings().Result;
                var apiResult = userProxy.GetApiResult().GetAwaiter().GetResult();
                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = 1,
                    Name   = "fanly"
                }).Wait();

                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = 1,
                    Name   = "fanly"
                }).Wait();

                var r = await userProxy.GetDictionary();
                var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();

                do
                {
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    //1w次调用
                    var watch = Stopwatch.StartNew();
                    for (var i = 0; i < 10000; i++)
                    {
                        //var a = userProxy.GetDictionary().Result;
                        var a = await userProxy.GetDictionary();
                        //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();
        }
예제 #5
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUserId("user");
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 var a = userProxy.GetDictionary().Result;
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.WriteLine("Press any key to continue, q to exit the loop...");
             var key = Console.ReadLine();
             if (key.ToLower() == "q")
             {
                 break;
             }
         } while (true);
     }).Wait();
 }
예제 #6
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         var result    = await userProxy.GetUserName(123);
     }).Wait();
 }
예제 #7
0
 public static void TestRabbitMq(IServiceProxyFactory serviceProxyFactory)
 {
     serviceProxyFactory.CreateProxy <IUserService>("User").PublishThroughEventBusAsync(new UserEvent()
     {
         Age    = 18,
         Name   = "fanly",
         UserId = 1
     });
     Console.WriteLine("Press any key to exit...");
     Console.ReadLine();
 }
예제 #8
0
        public static void TestThriftInvoker(IServiceProxyFactory serviceProxyFactory)
        {
            var proxy  = serviceProxyFactory.CreateProxy <IAsyncService>();
            var proxy1 = serviceProxyFactory.CreateProxy <IThirdAsyncService>();

            Task.Run(async() =>
            {
                do
                {
                    var result1 = await proxy.SayHelloAsync();
                    var result2 = await proxy1.SayHelloAsync();
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    var watch = Stopwatch.StartNew();

                    for (var i = 0; i < 10000; i++)
                    {
                        try
                        {
                            var result = await proxy.SayHelloAsync();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();

            Console.ReadLine();
        }
예제 #9
0
        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="serviceProxyFactory"></param>
        public static void Test(IServiceProxyFactory serviceProxyFactory)
        {
            Task.Run(async() =>
            {
                var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
                var v         = userProxy.GetUserId("fanly").GetAwaiter().GetResult();
                var fa        = userProxy.GetUserName(1).GetAwaiter().GetResult();
                var apiResult = userProxy.GetApiResult().GetAwaiter().GetResult();
                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = "1",
                    Name   = "fanly"
                }).Wait();

                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = "1",
                    Name   = "fanly"
                }).Wait();

                var r = await userProxy.GetDictionary();
                var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();

                do
                {
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    //1w次调用
                    var watch = Stopwatch.StartNew();
                    for (var i = 0; i < 10000; i++)
                    {
                        //var a = userProxy.GetDictionary().Result;
                        var a = userProxy.GetDictionary().Result;
                        //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();
        }
예제 #10
0
 /// <summary>
 /// 创建服务代理。
 /// </summary>
 /// <typeparam name="T">服务接口类型。</typeparam>
 /// <param name="serviceProxyFactory">服务代理工厂。</param>
 /// <param name="proxyType">代理类型。</param>
 /// <returns>服务代理实例。</returns>
 public static T CreateProxy <T>(this IServiceProxyFactory serviceProxyFactory, Type proxyType)
 {
     return((T)serviceProxyFactory.CreateProxy(proxyType));
 }