Esempio n. 1
0
        static void Main(string[] args)
        {
            //var tokenclient = new TokenClient("localhost", 9911);
            //var token = tokenclient.BuildStringWithExpire( "123" , DateTime.Now.AddYears(1) );
            //var token = tokenclient.BuildLongWithExpire(long.MaxValue / 2, DateTime.Now.AddYears(1));

            //token = tokenclient.BuildForLongs(new[] { 12u, (long)(DateTime.Now - Convert.ToDateTime("1970-1-1")).TotalSeconds });
            //var body2 = tokenclient.VerifyForLongs(token);


            while (true)
            {
                try
                {
                    NetClient client = new NetClient("127.0.0.1", 8911);
                    client.Dispose();
                    client = new NetClient("127.0.0.1", 8912);
                    client.Dispose();

                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }

            var cert = new X509Certificate2("../../../../pfx/client.pfx", "123456");

            using (var tran = new JMSClient(new NetAddress[] {
                new NetAddress("localhost", 8911)
            }, null, null, cert, cert))
            {
                tran.Timeout = 0;
                /////微服务 性能测试
                //var c1 = new Controller1(tran.GetMicroService("Controller1"));
                //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                //sw.Start();
                //for (int i = 0; i < 1000; i++)
                //{
                //    var ret22 = c1.test();
                //}
                //sw.Stop();
                //Console.WriteLine(sw.ElapsedMilliseconds);
                tran.SetHeader("auth", "WyJ7XCJkXCI6XCIxMjNcIixcImVcIjoxNjI5NTM4ODMxfSIsIkZFREE2MkU2RTg3RTZDNDhBOEI1NkExOURDNEUwQzQ2Il0=");
                //tran.SetHeader("auth", "AgB7AAAAAAAAAEzJIGEAAAAAOEZEMkUxODk4MjVFOEM5NzdGNjJGMEIyNkFERTBBRkQ=");

                //var locations = tran.ListMicroService("");//列出所有微服务
                //Console.WriteLine("微服务位置:{0}", locations.ToJsonString());

                var code = tran.GetMicroService("Service2").GetServiceClassCode("TestApplication", "Controller1");

                Controller1 controller1 = null;
                while (controller1 == null)
                {
                    Thread.Sleep(1000);
                    controller1 = tran.GetMicroService <Controller1>();
                }
                var Service2 = tran.GetMicroService("Service2");

                var ret = controller1.Test(123, "Jack.T");
                Console.WriteLine("调用结果:{0}", ret);



                controller1.Test2Async();

                var task = controller1.IntTestAsync();
                task.Wait();
                Console.WriteLine("异步调用结果:{0}", task.Result);

                ret = Service2.Invoke <string>("GetName", new TestObject {
                    Age = 12
                });

                tran.Commit();
            }
            Console.WriteLine("事务提交");
            Thread.Sleep(20000000);
        }
Esempio n. 2
0
        private async Task InvokeJms(HttpContext context, Dictionary <string, object> paramList)
        {
            string version = "";

            //检测返回结构: DataResult(默认), layui:
            bool bOK = context.Request.Headers.TryGetValue("Version", out StringValues strLayui);

            if (bOK)
            {
                version = strLayui.ToString().ToLower();
            }

            string         path     = context.Request.Path.ToString();
            InterfaceModel response = this.routeDict[path];
            string         exceMsg  = ""; //存储异常的存储过程名

            string Address = this.myConfig.GatewayAddress.Address;
            int    port    = this.myConfig.GatewayAddress.Port;

            JMSClient tran = new JMSClient(Address, port);

            try
            {
                DataRow dataPre  = null;
                string  result   = "";
                int     rowIndex = 0;
                int     count    = response.Steps.Count;
                foreach (FlowStepModel step in response.Steps)
                {
                    if (step.CommandText == "")
                    {
                        exceMsg = step.StepName + " 没有数据库语句,请维护";
                        tran.Rollback();
                        await this.InvokeException(exceMsg);

                        return;
                    }

                    //初始化参数
                    string CommandType = "Text";
                    switch (step.CommandType)
                    {
                    case "Fun":
                    case "Text":
                        CommandType = "Text";
                        break;

                    case "StoredProcedure":
                        CommandType = "StoredProcedure";
                        break;
                    }

                    if (string.IsNullOrEmpty(step.ServiceName))
                    {
                        exceMsg = step.StepName + ">>没有选服务名称!";
                        tran.Rollback();
                        await this.InvokeException(exceMsg);

                        return;
                    }

                    IMicroService service = tran.GetMicroService(step.ServiceName);
                    if (service == null)
                    {
                        tran.Rollback();
                        await this.InvokeException($"无法从{Address}网关中获取服务>ErpService");

                        return;
                    }

                    JmsCommand dbCommand = new JmsCommand();
                    dbCommand.DataBase    = step.DataBase;
                    dbCommand.CommandType = CommandType;
                    dbCommand.CommandText = step.CommandText;

                    Dictionary <string, object> paralist = CreateParamJms(dataPre, step, paramList, out exceMsg);
                    if (exceMsg != "")
                    {
                        //创建参数出错
                        await this.InvokeException(exceMsg);

                        return;
                    }
                    dbCommand.Parameters = paralist;

                    try
                    {
                        //执行Sql
                        if (rowIndex == count - 1) //最后一步
                        {
                            List <FilterCondition> filters = null;
                            if (paramList.ContainsKey(_ReqFilter))
                            {
                                JArray ja = (JArray)paramList[_ReqFilter];
                                filters = ja.ToObject <List <FilterCondition> >();
                            }

                            if (version == "layui")
                            {
                                result = this.ExecSqlJmsLayui(response, service, dbCommand, filters);
                            }
                            else
                            {
                                result = this.ExecSqlJms(response, service, dbCommand, filters);
                            }
                        }
                        else
                        {
                            //如果不是最后一步,存储当前步结果
                            DataSet ds = service.Invoke <DataSet>("Fill", dbCommand);
                            if (ds.Tables.Count > 0 && ds.Tables[ds.Tables.Count - 1].Rows.Count > 0)
                            {
                                DataTable dt = ds.Tables[ds.Tables.Count - 1];
                                dataPre = dt.Rows[0];
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        exceMsg = response.Url + ">>" + step.StepName + ">>" + ex.Message;
                        this.logger.LogError(exceMsg);
                        throw new Exception(exceMsg);
                    }

                    rowIndex++;
                }

                tran.Commit();

                await this.WriteAsync(result);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                await this.InvokeException(ex.Message);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //var tokenclient = new TokenClient("localhost", 9911);
            //var token = tokenclient.BuildForString(new { userid = 12, expire = 12u }.ToJsonString());
            //var body = tokenclient.VerifyForString(token);

            //token = tokenclient.BuildForLongs(new[] { 12u, (long)(DateTime.Now - Convert.ToDateTime("1970-1-1")).TotalSeconds });
            //var body2 = tokenclient.VerifyForLongs(token);


            while (true)
            {
                try
                {
                    NetClient client = new NetClient("127.0.0.1", 8911);
                    client.Dispose();
                    client = new NetClient("127.0.0.1", 8912);
                    client.Dispose();

                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }

            var cert = new X509Certificate2("../../../../pfx/client.pfx", "123456");

            using (var tran = new JMSClient(new NetAddress[] {
                new NetAddress("localhost", 8911)
            }, null, null, cert, cert))
            {
                tran.Timeout = 0;
                /////微服务 性能测试
                //var c1 = new Controller1(tran.GetMicroService("Controller1"));
                //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                //sw.Start();
                //for (int i = 0; i < 1000; i++)
                //{
                //    var ret22 = c1.test();
                //}
                //sw.Stop();
                //Console.WriteLine(sw.ElapsedMilliseconds);

                tran.SetHeader("auth", "123456789");

                //var locations = tran.ListMicroService("");//列出所有微服务
                //Console.WriteLine("微服务位置:{0}", locations.ToJsonString());

                var code = tran.GetMicroService("Service2").GetServiceClassCode("TestApplication", "Controller1");

                Controller1 controller1 = null;
                while (controller1 == null)
                {
                    Thread.Sleep(1000);
                    controller1 = tran.GetMicroService <Controller1>();
                }
                var Service2 = tran.GetMicroService("Service2");

                var ret = controller1.Test(123, "Jack.T");
                Console.WriteLine("调用结果:{0}", ret);

                controller1.Test2Async();

                var task = controller1.IntTestAsync();
                task.Wait();
                Console.WriteLine("异步调用结果:{0}", task.Result);

                ret = Service2.Invoke <string>("GetName", new { Name = "Jack" });

                tran.Commit();
            }
            Console.WriteLine("事务提交");
            Thread.Sleep(20000000);
        }