Beispiel #1
0
        /// <summary>
        /// Daemon工作状态的主方法
        /// </summary>
        /// <param name="args"></param>
        public static void StartUp(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
            {
                if (Monitor.State)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} AnnoCenter Service is being stopped·····");
                    Monitor.Stop();
                    Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} AnnoCenter The service has stopped!");
                    Console.ResetColor();
                }
            };
            Monitor.Start();
            var tc = ThriftConfig.CreateInstance();

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}:服务注册、发现、健康检查、负载均衡中心,端口:{tc.Port}(AnnoCenter)已启动!");
            Console.ResetColor();
            //阻止daemon进程退出
            while (true)
            {
                tc.ServiceInfoList.Distinct().Where(s => s.Checking == false).ToList().ForEach(service =>
                {
                    Task.Run(() => { Distribute.HealthCheck(service); });
                });
                Thread.Sleep(3000);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Daemon工作状态的主方法
        /// </summary>
        /// <param name="args"></param>
        /// <param name="Notice">通知</param>
        /// <param name="ChangeNotice">变更通知</param>
        public static void StartUp(string[] args, Action <ServiceInfo, NoticeType> Notice = null, Action <ServiceInfo, ServiceInfo> ChangeNotice = null)
        {
            var tc = ThriftConfig.CreateInstance();

            OutputLogo(tc);
            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
            {
                if (Monitor.State)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} AnnoCenter Service is being stopped·····");
                    Monitor.Stop();
                    Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} AnnoCenter The service has stopped!");
                    Console.ResetColor();
                }
            };
            Monitor.Start();
            #region  务上线 下线 变更通知

            tc.ChangeNotice += (ServiceInfo newService, ServiceInfo oldService) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    ChangeNotice?.Invoke(newService, oldService);
                }
                finally { }
            };
            tc.OnlineNotice += (ServiceInfo service, NoticeType noticeType) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    Notice?.Invoke(service, noticeType);
                }
                finally { }
            };
            Distribute.CheckNotice += (ServiceInfo service, NoticeType noticeType) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    Notice?.Invoke(service, noticeType);
                }
                finally { }
            };
            #endregion
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}:服务注册、发现、健康检查、负载均衡中心,端口:{tc.Port}(AnnoCenter)已启动!");
            Console.ResetColor();
            //阻止daemon进程退出
            while (true)
            {
                tc.ServiceInfoList.Distinct().Where(s => s.Checking == false).ToList().ForEach(service =>
                {
                    Task.Run(() => { Distribute.HealthCheck(service); });
                });
                Thread.Sleep(3000);
            }
        }
Beispiel #3
0
        public override Task <BrokerReply> Add_broker(Micro request, ServerCallContext context)
        {
            BrokerReply  reply = new BrokerReply();
            ThriftConfig tc    = ThriftConfig.CreateInstance();

            tc.Add(request);
            reply.Reply = "1";
            return(Task.FromResult(reply));
        }
Beispiel #4
0
 public static void Start()
 {
     ThriftConfig tc = ThriftConfig.CreateInstance();
     TServerSocket serverTransport = new TServerSocket(tc.Port, 0, true);
     BrokerCenter.Processor processor = new BrokerCenter.Processor(new BusinessImpl());
     _server = new TThreadedServer(processor, serverTransport,Log.Log.ConsoleWriteLine,200);
     new Thread(_server.Serve) { IsBackground = true }.Start();//开启业务服务
     State = true;
 }
Beispiel #5
0
 /// <summary>
 /// 获取实例
 /// </summary>
 /// <returns></returns>
 public static ThriftConfig CreateInstance()
 {
     if (_instance == null)
     {
         lock (LockHelper)
         {
             if (_instance == null)
             {
                 _instance = new ThriftConfig();
             }
         }
     }
     return(_instance);
 }
Beispiel #6
0
        public static void Start()
        {
            ThriftConfig tc = ThriftConfig.CreateInstance();

            //TServerSocket serverTransport = new TServerSocket(tc.Port, 0, true);
            _server = new Grpc.Core.Server
            {
                Services = { BrokerCenter.BindService(new BusinessImpl()) },
                Ports    = { new ServerPort("0.0.0.0", tc.Port, ServerCredentials.Insecure) }
            };
            new Thread(_server.Start)
            {
                IsBackground = true
            }.Start();                                                //开启业务服务
            State = true;
        }
Beispiel #7
0
        private static void OutputLogo(ThriftConfig tc)
        {
            var logo = "\r\n";

            logo += " -----------------------------------------------------------------------------\r\n";
            logo +=
                $@"                                                _                    
     /\                           ___          (_)                   
    /  \    _ __   _ __    ___   ( _ )  __   __ _  _ __    ___  _ __ 
   / /\ \  | '_ \ | '_ \  / _ \  / _ \/\\ \ / /| || '_ \  / _ \| '__|
  / ____ \ | | | || | | || (_) || (_>  < \ V / | || |_) ||  __/| |   
 /_/    \_\|_| |_||_| |_| \___/  \___/\/  \_/  |_|| .__/  \___||_|   
                                                  | |                
                                                  |_|                
                                    [{DateTime.Now:yyyy-MM-dd HH:mm:ss}] grpc center
";
            logo += " -----------------------------------------------------------------------------\r\n";
            logo += $" {"Center Port".PadRight(17, ' ')}{tc.Port} \r\n";
            logo += $" {"Author".PadRight(17, ' ')}YanMing.Du \r\n";
            logo += $" {"Version".PadRight(17, ' ')}[{ typeof(Center.Bootstrap).Assembly.GetName().Version}]\r\n";
            logo += $" {"Repository".PadRight(17, ' ')}https://github.com/duyanming/anno.core \r\n";
            logo += " -----------------------------------------------------------------------------\r\n";
            Log.WriteLineNoDate(logo);
        }
Beispiel #8
0
        private static void OutputLogo(ThriftConfig tc)
        {
            var logo = "\r\n";

            logo += " -----------------------------------------------------------------------------\r\n";
            logo +=
                @"                                                _                    
     /\                           ___          (_)                   
    /  \    _ __   _ __    ___   ( _ )  __   __ _  _ __    ___  _ __ 
   / /\ \  | '_ \ | '_ \  / _ \  / _ \/\\ \ / /| || '_ \  / _ \| '__|
  / ____ \ | | | || | | || (_) || (_>  < \ V / | || |_) ||  __/| |   
 /_/    \_\|_| |_||_| |_| \___/  \___/\/  \_/  |_|| .__/  \___||_|   
                                                  | |                
                                                  |_|                
                                            anno&viper  thrift center 
";
            logo += " -----------------------------------------------------------------------------\r\n";
            logo += $" Center Port      {tc.Port} \r\n";
            logo += $" Author           YanMing.Du \r\n";
            logo += $" Version          [{ typeof(Center.Bootstrap).Assembly.GetName().Version}]\r\n";
            logo += $" Repository       https://github.com/duyanming/anno.core \r\n";
            logo += " -----------------------------------------------------------------------------\r\n";
            System.Console.WriteLine(logo);
        }
Beispiel #9
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool add_broker(Dictionary <string, string> input)
        {
            ThriftConfig tc = ThriftConfig.CreateInstance();

            return(tc.Add(input));
        }
Beispiel #10
0
        /// <summary>
        /// Daemon工作状态的主方法
        /// </summary>
        /// <param name="args"></param>
        /// <param name="Notice">通知</param>
        /// <param name="ChangeNotice">变更通知</param>
        public static void StartUp(string[] args, Action <ServiceInfo, NoticeType> Notice = null, Action <ServiceInfo, ServiceInfo> ChangeNotice = null)
        {
            var tc = ThriftConfig.CreateInstance();

            OutputLogo(tc);
            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
            {
                if (Monitor.State)
                {
                    Log.WriteLine("AnnoCenter Service is being stopped·····", ConsoleColor.DarkGreen);
                    Monitor.Stop();
                    Log.WriteLine("AnnoCenter The service has stopped!", ConsoleColor.DarkGreen);
                }
            };
            Monitor.Start();
            #region  务上线 下线 变更通知

            tc.ChangeNotice += (ServiceInfo newService, ServiceInfo oldService) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    ChangeNotice?.Invoke(newService, oldService);
                }
                finally { }
            };
            tc.OnlineNotice += (ServiceInfo service, NoticeType noticeType) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    Notice?.Invoke(service, noticeType);
                }
                finally { }
            };
            Distribute.CheckNotice += (ServiceInfo service, NoticeType noticeType) =>
            {
                try
                {
                    tc.RefreshServiceMd5();
                    Notice?.Invoke(service, noticeType);
                }
                finally { }
            };
            #endregion
            Log.WriteLine($"服务注册、发现、健康检查、KV存储、API文档、负载均衡中心,端口:{tc.Port}(AnnoCenter)已启动!", ConsoleColor.DarkGreen);
            CronDaemon.AddJob("*/5 * * * * ? *", () =>
            {
                Parallel.ForEach(
                    tc.ServiceInfoList.Distinct().Where(s => s.Checking == false)
                    , new ParallelOptions()
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                }
                    , service =>
                {
                    Task.Factory.StartNew(() =>
                    {
                        Distribute.HealthCheck(service);
                    }, TaskCreationOptions.LongRunning);
                });
            });
            CronDaemon.Start();
            //阻止daemon进程退出
            new AutoResetEvent(false).WaitOne();
        }