Ejemplo n.º 1
0
        /// <summary>
        ///服务启动后将服务Api文档写入注册中心
        ///
        ///增加自己的服务的时候只用复制下面的代码就可以不用做修改
        /// </summary>
        public static void ApiDoc()
        {
            List <AnnoData> routings = new List <AnnoData>();

            foreach (var item in EngineData.Routing.Routing.Router)
            {
                if (item.Value.RoutMethod.Name == "get_ActionResult")
                {
                    continue;
                }
                var parameters = item.Value.RoutMethod.GetParameters().ToList().Select(it =>
                {
                    var parameter = new ParametersValue
                    {
                        Name = it.Name, Position = it.Position, ParameterType = it.ParameterType.FullName
                    };
                    var pa = it.GetCustomAttributes <AnnoInfoAttribute>().ToList();
                    if (pa.Any())
                    {
                        parameter.Desc = pa.First().Desc;
                    }
                    return(parameter);
                }).ToList();
                string methodDesc          = String.Empty;
                var    mAnnoInfoAttributes = item.Value.RoutMethod.GetCustomAttributes <AnnoInfoAttribute>().ToList();
                if (mAnnoInfoAttributes.Count > 0)
                {
                    methodDesc = mAnnoInfoAttributes.First().Desc;
                }
                routings.Add(new AnnoData()
                {
                    App   = Anno.Const.SettingService.AppName,
                    Id    = $"{Anno.Const.SettingService.AppName}:{item.Key}",
                    Value = Newtonsoft.Json.JsonConvert.SerializeObject(new DataValue {
                        Desc = methodDesc, Name = item.Value.RoutMethod.Name, Parameters = parameters
                    })
                });
            }
            Dictionary <string, string> input = new Dictionary <string, string>();

            input[StorageCommand.COMMAND] = StorageCommand.APIDOCCOMMAND;
            input.Add(CONST.Opt, CONST.DeleteByApp);
            input.Add(CONST.App, Anno.Const.SettingService.AppName);
            var del = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));

            if (del.Status == false)
            {
                Log.Log.Error(del);
            }
            input.Clear();
            input[StorageCommand.COMMAND] = StorageCommand.APIDOCCOMMAND;
            input.Add(CONST.Opt, CONST.UpsertBatch);
            input.Add(CONST.Data, Newtonsoft.Json.JsonConvert.SerializeObject(routings));
            var rlt = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));

            if (rlt.Status == false)
            {
                Log.Log.Error(rlt);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改服务权重
        /// </summary>
        public void Handle8()
        {
            Init();
To:
            Console.Write("请输入权重:");
            long.TryParse(Console.ReadLine(), out long weight);
            Dictionary <string, string> input = new Dictionary <string, string>();

            input[StorageCommand.COMMAND] = StorageCommand.ANNOMICROSERVICE;
            input["ip"]     = "10.128.3.109";
            input["port"]   = "6659";
            input["weight"] = weight.ToString();
            StorageEngine.Invoke(input);
            for (int i = 0; i < 10; i++)
            {
                Dictionary <string, string> inputx = new Dictionary <string, string>();
                inputx.Add("channel", "Anno.Plugs.HelloWorld");
                inputx.Add("router", "HelloWorldTask");
                inputx.Add("method", "TaskActionResult");
                var x = Connector.BrokerDns(inputx);
                Console.WriteLine(x);
                Task.Delay(1000).Wait();
            }
            goto To;
        }
Ejemplo n.º 3
0
        public ActionResult GetRoutingInfo([AnnoInfo(Desc = "服务名称")] string appName)
        {
            Dictionary <string, string> input = new Dictionary <string, string>();

            input.Add(StorageCommand.COMMAND, StorageCommand.APIDOCCOMMAND);
            input.Add(CONST.Opt, CONST.FindByApp);
            input.Add(CONST.App, appName);
            string rlt = StorageEngine.Invoke(input);
            List <AnnoDataOutPut> annoDataOutPuts = new List <AnnoDataOutPut>();
            RoutingInfomationDto  routing         = Newtonsoft.Json.JsonConvert.DeserializeObject <RoutingInfomationDto>(rlt);

            if (routing.Data != null && routing.Data.Count > 0)
            {
                routing.Data.ForEach(d =>
                {
                    annoDataOutPuts.Add(new AnnoDataOutPut()
                    {
                        App     = d.App,
                        Channel = d.Channel,
                        Router  = d.Router,
                        Method  = d.Method,
                        Desc    = d.ValueObj.Desc,
                        Value   = d.ValueObj
                    });
                });
            }
            return(new ActionResult(true, annoDataOutPuts.OrderBy(d => d.Channel).ThenBy(d => d.Router).ThenBy(d => d.Method)));
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Contains("-help"))
            {
                Log.ConsoleWriteLine(@"
启动参数:
	-p 6659		设置启动端口
	-xt 200		设置服务最大线程数
	-t 20000		设置超时时间(单位毫秒)
	-w 1		设置权重
	-h 192.168.0.2	设置服务在注册中心的地址
	-tr false		设置调用链追踪是否启用"            );
                return;
            }
            Bootstrap.StartUp(args, () =>
            {
                //Anno.Const.SettingService.TraceOnOff = true;
                var autofac = IocLoader.GetAutoFacContainerBuilder();
                autofac.RegisterType(typeof(RpcConnectorImpl)).As(typeof(IRpcConnector)).SingleInstance();
            }, () =>
            { //startUp  CallBack
                List <AnnoData> routings = new List <AnnoData>();
                foreach (var item in Anno.EngineData.Routing.Routing.Router)
                {
                    if (item.Value.RoutMethod.Name == "get_ActionResult")
                    {
                        continue;
                    }
                    var parameters = item.Value.RoutMethod.GetParameters().ToList().Select(it =>
                    {
                        var parameter = new ParametersValue
                        {
                            Name = it.Name, Position = it.Position, ParameterType = it.ParameterType.FullName
                        };
                        var pa = it.GetCustomAttributes <AnnoInfoAttribute>().ToList();
                        if (pa.Any())
                        {
                            parameter.Desc = pa.First().Desc;
                        }
                        return(parameter);
                    }).ToList();
                    string methodDesc       = String.Empty;
                    var mAnnoInfoAttributes = item.Value.RoutMethod.GetCustomAttributes <AnnoInfoAttribute>().ToList();
                    if (mAnnoInfoAttributes.Count > 0)
                    {
                        methodDesc = mAnnoInfoAttributes.First().Desc;
                    }
                    routings.Add(new AnnoData()
                    {
                        App   = Anno.Const.SettingService.AppName,
                        Id    = $"{Anno.Const.SettingService.AppName}:{item.Key}",
                        Value = Newtonsoft.Json.JsonConvert.SerializeObject(new DataValue {
                            Desc = methodDesc, Name = item.Value.RoutMethod.Name, Parameters = parameters
                        })
                    });
                }
                Dictionary <string, string> input = new Dictionary <string, string>();
                input.Add(CONST.Opt, CONST.DeleteByApp);
                input.Add(CONST.App, Anno.Const.SettingService.AppName);
                var del = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));
                if (del.Status == false)
                {
                    Anno.Log.Log.Error(del);
                }
                input.Clear();
                input.Add(CONST.Opt, CONST.UpsertBatch);
                input.Add(CONST.Data, Newtonsoft.Json.JsonConvert.SerializeObject(routings));
                var rlt = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));
                if (rlt.Status == false)
                {
                    Anno.Log.Log.Error(rlt);
                }
            });
        }
Ejemplo n.º 5
0
 static void Main(string[] args)
 {
     Console.Title = "AnnoTraceContainer";
     Bootstrap.StartUp(args, () =>
     {
         Anno.Const.SettingService.TraceOnOff = false;
         var cb = IocLoader.GetAutoFacContainerBuilder();
         cb.RegisterType(typeof(RpcConnectorImpl)).As(typeof(IRpcConnector)).SingleInstance();
     }, () =>
     { //startUp  CallBack
         List <AnnoData> routings = new List <AnnoData>();
         foreach (var item in Anno.EngineData.Routing.Routing.Router)
         {
             if (item.Value.RoutMethod.Name == "get_ActionResult")
             {
                 continue;
             }
             var parameters = item.Value.RoutMethod.GetParameters().ToList().Select(it => new ParametersValue {
                 Name = it.Name, Position = it.Position, ParameterType = it.ParameterType.FullName
             }).ToList();
             routings.Add(new AnnoData()
             {
                 App   = Anno.Const.SettingService.AppName,
                 Id    = $"{Anno.Const.SettingService.AppName}:{item.Key}",
                 Value = Newtonsoft.Json.JsonConvert.SerializeObject(new DataValue {
                     Name = item.Value.RoutMethod.Name, Parameters = parameters
                 })
             });
         }
         Dictionary <string, string> input = new Dictionary <string, string>();
         input.Add(CONST.Opt, CONST.DeleteByApp);
         input.Add(CONST.App, Anno.Const.SettingService.AppName);
         var del = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));
         if (del.Status == false)
         {
             Anno.Log.Log.Error(del);
         }
         input.Clear();
         input.Add(CONST.Opt, CONST.UpsertBatch);
         input.Add(CONST.Data, Newtonsoft.Json.JsonConvert.SerializeObject(routings));
         var rlt = Newtonsoft.Json.JsonConvert.DeserializeObject <AnnoDataResult>(StorageEngine.Invoke(input));
         if (rlt.Status == false)
         {
             Anno.Log.Log.Error(rlt);
         }
     });
 }