Example #1
0
        private static void Main(string[] args)
        {
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();                                            //
                    option.AddRelateService();                                             //添加支持服务代理远程调用
                    option.AddConfigurationWatch();                                        //添加同步更新配置文件的监听处理
                                                                                           // option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181")); //使用Zookeeper管理
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));             //使用Consul管理
                    option.UseDotNettyTransport();                                         //使用Netty传输
                    option.UseRabbitMQTransport();                                         //使用rabbitmq 传输
                    option.AddRabbitMQAdapt();                                             //基于rabbitmq的消费的服务适配
                                                                                           //  option.UseProtoBufferCodec();//基于protobuf序列化
                    option.UseMessagePackCodec();                                          //基于MessagePack序列化
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current)); //初始化注入容器
                });
            })
                       .SubscribeAt() //消息订阅
                                      //.UseServer("127.0.0.1", 98)
                                      //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                                      //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options =>
            {
                options.Ip   = "127.0.0.1";
                options.Port = 98;
                //options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);
                //options.Ip = "0.0.0.0";
                options.ExecutionTimeoutInMilliseconds = 30000;                                                       //执行超时时间
                options.Strategy                        = (int)StrategyType.Failover;                                 //容错策略使用故障切换
                options.RequestCacheEnabled             = true;                                                       //开启缓存(只有通过接口代理远程调用,才能启用缓存)
                options.Injection                       = "return null";                                              //注入方式
                options.InjectionNamespaces             = new string[] { "Surging.IModuleServices.Common" };          //脚本注入使用的命名空间
                options.BreakeErrorThresholdPercentage  = 50;                                                         //错误率达到多少开启熔断保护
                options.BreakeSleepWindowInMilliseconds = 60000;                                                      //熔断多少毫秒后去尝试请求
                options.BreakerForceClosed              = false;                                                      //是否强制关闭熔断
                options.BreakerRequestVolumeThreshold   = 20;                                                         //10秒钟内至少多少请求失败,熔断器才发挥起作用
                options.MaxConcurrentRequests           = 100000;                                                     //支持最大并发
                options.ShuntStrategy                   = AddressSelectorMode.Polling;                                //使用轮询负载分流策略
                options.NotRelatedAssemblyFiles         = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*"; //排除无需依赖注册
            })
                       .UseLog4net("Configs/log4net.config")                                                          //使用log4net记录日志
                                                                                                                      //.UseNLog(LogLevel.Error, "Configs/NLog.config")// 使用NLog 记录日志
                                                                                                                      //.UseLog4net(LogLevel.Error) //使用log4net记录日志
                                                                                                                      //.UseLog4net()  //使用log4net记录日志
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))                    //使用eventBusSettings.json文件进行配置
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false))                          //使用cacheSettings.json文件进行配置
                       .UseProxy()                                                                                    //使用Proxy
                                                                                                                      //.UseStartup<Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient()
                    .AddCache();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("${surgingpath}|surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseClient()
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.TestForRoutePath(ServiceLocator.GetService <IServiceProxyProvider>());
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(option =>
            {
                option.Initialize();
                option.RegisterServices();
                option.RegisterRepositories();
                option.RegisterModules();
                option.RegisterServiceBus();
            })
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseServer("127.0.0.1", 98)
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    option.AddRelateService();
                    option.AddConfigurationWatch();
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    option.AddCache();
                    //option.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //    kafkaOption.LogConnectionClose = false;
                    //    kafkaOption.MaxQueueBuffering = 10;
                    //    kafkaOption.MaxSocketBlocking = 10;
                    //    kafkaOption.EnableAutoCommit = false;
                    //});
                    //option.AddKafkaMQAdapt();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       // .UseLog4net(LogLevel.Error, "Configs/log4net.config")
                       .UseNLog(LogLevel.Error, "Configs/NLog.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options =>
            {
                // options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
            })
                       .UseServiceCache()
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(option =>
            {
                option.Initialize();
                option.RegisterServices();
                option.RegisterRepositories();
                option.RegisterModules();
            })
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient();
                    option.AddClientIntercepted(typeof(CacheProviderInterceptor));
                    // option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .UseClient()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient()
                    .AddCache();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("${surgingpath}|surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseNLog(LogLevel.Error)
                       .UseClient()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.Test(ServiceLocator.GetService <IServiceProxyFactory>());
                //Startup.TestRabbitMq(ServiceLocator.GetService<IServiceProxyFactory>());
                // Startup.TestForRoutePath(ServiceLocator.GetService<IServiceProxyProvider>());
                /// test Parallel
                //var connectionCount = 200000;
                //StartRequest(connectionCount);
                //Console.ReadLine();
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient();
                    option.AddClientIntercepted(typeof(CacheProviderInterceptor));
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .UseLog4net()
                       .UseClient()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.Test(ServiceLocator.GetService <IServiceProxyFactory>());
                //Startup.TestRabbitMq(ServiceLocator.GetService<IServiceProxyFactory>());
                // Startup.TestForRoutePath(ServiceLocator.GetService<IServiceProxyProvider>());
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Client, Hello World!");

            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.RegisterType <MessagePackTransportMessageCodecFactory>().As <ITransportMessageCodecFactory>().SingleInstance();
                builder.RegisterType(typeof(ClientExecutor)).As(typeof(IServiceExecutor)).SingleInstance();
                builder.Register(provider =>
                {
                    IServiceExecutor serviceExecutor = null;
                    if (provider.IsRegistered(typeof(IServiceExecutor)))      // 没有注册客户端接收消息执行器,因此一直为空
                    {
                        serviceExecutor = provider.Resolve <IServiceExecutor>();
                    }
                    return(new DotNettyTransportClientFactory(provider.Resolve <ITransportMessageCodecFactory>(),
                                                              provider.Resolve <ILogger <DotNettyTransportClientFactory> >(),
                                                              serviceExecutor));
                }).As(typeof(ITransportClientFactory)).SingleInstance();
            })
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.Test();
            }
            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseLog4net("Configs/log4net.config")
                       .UseServer("127.0.0.1", 98)
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    .UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"))
                    .AddServiceEngine(typeof(SurgingServiceEngine));
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .UseServer(options => { })
                       .UseConsoleLifetime()
                       .UseNLog(LogLevel.Trace, "NLog.config")// 使用NLog 记录日志
                       .Configure(build =>
                                  build.AddCacheFile("${cachepath}|Configs/cacheSettings.json", basePath: AppContext.BaseDirectory, optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("${surgingpath}|Configs/surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Console.WriteLine($"[{DateTime.Now.ToString()}]: Start to build Client......");
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient()
                    .AddClientIntercepted(typeof(CacheProviderInterceptor))     //20180706
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseConsulManager(new ConfigInfo("47.106.78.196:8500"))     //20180706
                    .UseDotNettyTransport()
                    //.UseRabbitMQTransport() //comment by zony on 20180704
                    .AddCache()     //20180706
                    //.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //});
                    //.UseProtoBufferCodec()
                    .UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                    //builder.RegisterType(typeof(Modules.Common.Domain.UserService)).As<IUserService>(); //Surging.Modules.Common的引用于20180706添加,临时测试
                });
            })
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))                 //20180706
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true)) //20180706
                       .UseNLog(LogLevel.Trace)
                                                                                                                   // .UseLog4net(LogLevel.Error)
                       .UseServiceCache()                                                                          //20180706
                       .UseProxy()                                                                                 //20180706
                       .UseClient()                                                                                //20180706
                       .UseStartup <Startup>()
                       .Build();

            Console.WriteLine($"[{DateTime.Now.ToString()}]: Start to run Client......");
            using (host.Run())
            {
                Console.WriteLine($"[{DateTime.Now.ToString()}]: Run Client successfully.");
                Console.WriteLine($"Thread Id: {Environment.CurrentManagedThreadId}");

                //Startup.Test(ServiceLocator.GetService<IServiceProxyFactory>());
                //Startup.TestRabbitMq(ServiceLocator.GetService<IServiceProxyFactory>());
                //Startup.TestForRoutePath(ServiceLocator.GetService<IServiceProxyProvider>());
                //test Parallel
                //var connectionCount = 200000;
                //StartRequest(connectionCount);

                //Startup.TestLocalService(); //测试本地模块和服务调用

                Startup.TestRemoteService();

                Console.WriteLine($"[{DateTime.Now.ToString()}]: ReadLine to exit.");
                Console.ReadLine();
            }
        }
Example #12
0
        private static void Main(string[] args)
        {
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddClientProxy()
                    .AddRelateServiceRuntime()
                    .AddConfigurationWatch()
                    .AddServiceEngine(typeof(SurgingServiceEngine))
                    .AddClientIntercepted(typeof(CacheProviderInterceptor))
                    ;

                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .ConfigureLogging(loggging =>
            {
                loggging.AddConfiguration(
                    AppConfig.GetSection("Logging"));
            })
                       .UseServer(options => { })
                       .UseConsoleLifetime()
                       .Configure(build =>
            {
#if DEBUG
                build.AddCacheFile("${cachePath}|/app/configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|/app/configs/surgingSettings.json", optional: false, reloadOnChange: true);
                //   build.AddEventBusFile("${eventBusPath}|/app/configs/eventBusSettings.json", optional: false);
                build.AddConsulFile("${consulPath}|/app/configs/consul.json", optional: false, reloadOnChange: true);
#else
                build.AddCacheFile("${cachePath}|configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|configs/surgingSettings.json", optional: false, reloadOnChange: true);
                //   build.AddEventBusFile("configs/eventBusSettings.json", optional: false);
                build.AddConsulFile("configs/consul.json", optional: false, reloadOnChange: true);
#endif
            })
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务主机启动成功{DateTime.Now}。");

#if DEBUG
                //if (SurgingConfig.ServerOptions.InitAction)
                //{
                //    Startup.InitActions();
                //}
#endif
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClientIntercepted(typeof(CacheProviderInterceptor));
                    option.AddServiceRuntime();
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("local.rancher.com:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseLog4net("Configs/log4net.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options => {
                options.Ip    = "127.0.0.1";
                options.Port  = 98;
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
                //options.NotRelatedAssemblyFiles = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*";

                //options.Ip = "127.0.0.1";
                //options.Port = 98;
                //options.ExecutionTimeoutInMilliseconds = 30000;
                //options.Strategy = StrategyType.Failover; //容错策略使用故障切换
                //options.RequestCacheEnabled = true; //开启缓存(只有通过接口代理远程调用,才能启用缓存)
                //options.Injection = "return null"; //注入方式
                //options.InjectionNamespaces = new string[] { "Bill.WMS.IModuleServices.Users" }; //脚本注入使用的命名空间
                //options.BreakeErrorThresholdPercentage = 50;  //错误率达到多少开启熔断保护
                //options.BreakeSleepWindowInMilliseconds = 60000; //熔断多少毫秒后去尝试请求
                //options.BreakerForceClosed = false;   //是否强制关闭熔断
                //options.BreakerRequestVolumeThreshold = 20;//10秒钟内至少多少请求失败,熔断器才发挥起作用
                //options.MaxConcurrentRequests = 100000;//支持最大并发
            })
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    option.AddRelateService();
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    //option.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //    kafkaOption.LogConnectionClose = false;
                    //    kafkaOption.MaxQueueBuffering = 10;
                    //    kafkaOption.MaxSocketBlocking = 10;
                    //    kafkaOption.EnableAutoCommit = false;
                    //});
                    //option.AddKafkaMQAdapt();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseLog4net("Configs/log4net.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options =>
            {
                // options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);
                options.Ip    = "127.0.0.1";
                options.Port  = 98;
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
                options.NotRelatedAssemblyFiles        = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*";
            })
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            var host = new ServiceHostBuilder()
                       .AddConfiguration(o => o.SetBasePath(Directory.GetCurrentDirectory())
                                         .AddJsonFile("appsettings.json")
                                         .AddEnvironmentVariables()
                                         )
                       .SetStartup <Startup>()
                       .Build();


            host.Run();
        }
Example #16
0
        public static void Main(string[] args)
        {
            // create initial broker
            var broker = new MessageBroker();

            // put first message on the queue
            var testMessage = new Message {
                Body = "Call siri"
            };

            broker.SendMessage("cortana", testMessage);

            var host = new ServiceHostBuilder()
                       // Add Configuration sources
                       .AddEnvironmentConfiguration()
                       .AddJsonConfiguration("logging.json", false, true)
                       .AddIniConfiguration("siri.ini", false, true)
                       .AddXmlConfiguration("cortana.xml", false, true)
                       .AddJsonConfiguration("alexa.json", false, true)
                       .AddCommandLine(args)

                       // Add configuration Types to DI
                       .Configure <SiriOptions>("Siri")
                       .Configure <AlexaOptions>("Alexa")
                       .Configure <CortanaOptions>("Cortana")

                       // Add Logging services
                       .AddLogging("Loging", builder =>
            {
                builder
                .AddFilter("Microsoft", LogLevel.Error)
                .AddFilter("System", LogLevel.Error)
                .AddConsole()
                .AddDebug();
            })

                       // Add normal dependencies
                       .TryAddSingleton <IMessageBroker>(broker)

                       // Configure the services to run
                       .IncludeService <SiriService>()
                       .IncludeService <AlexaService>()
                       .IncludeService <CortanaService>()

                       // Build the ServiceHost
                       .Build();

            // Start the ServiceHost
            host.Run();
        }
Example #17
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient()
                    .AddClientIntercepted(typeof(CacheProviderInterceptor))
                    .AddClientIntercepted(typeof(LogProviderInterceptor))
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseConsulManager(new ConfigInfo("127.0.0.1:8500"))
                    .UseDotNettyTransport()
                    .UseRabbitMQTransport()
                    .AddCache()
                    //.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //});
                    //.UseProtoBufferCodec()
                    .UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .Configure(build =>
                                  build.AddEventBusFile("eventBusSettings.json", optional: false))
                       .Configure(build =>
                                  build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .UseNLog(LogLevel.Error)
                       // .UseLog4net(LogLevel.Error)
                       .UseServiceCache()
                       .UseProxy()
                       .UseClient()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.Test(ServiceLocator.GetService <IServiceProxyFactory>());
                //Startup.TestRabbitMq(ServiceLocator.GetService<IServiceProxyFactory>());
                // Startup.TestForRoutePath(ServiceLocator.GetService<IServiceProxyProvider>());
                /// test Parallel
                //var connectionCount = 250000;
                //var requestThread = new Thread(() => StartRequest(connectionCount)) { IsBackground = true };
                //requestThread.Start();
                //Console.ReadLine();
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            //  Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .AddServiceEngine(typeof(SurgingServiceEngine))
                    .AddClientIntercepted(typeof(CacheProviderInterceptor));
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .ConfigureLogging(logger =>
            {
                logger.AddConfiguration(
                    AppConfig.GetSection("Logging"));
            })
                       .UseServer(options => { })
                       .UseConsoleLifetime()
                       .Configure(build =>
            {
#if DEBUG
                build.AddCacheFile("${cachePath}|/app/configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|/app/configs/surgingSettings.json", optional: false, reloadOnChange: true);
                build.AddEventBusFile("${eventBusPath}|/app/configs/eventBusSettings.json", optional: false, reloadOnChange: true);
                build.AddConsulFile("${consulPath}|/app/configs/consul.json", optional: false, reloadOnChange: true);
                build.AddZookeeperFile("${zookeeperPath}|/app/configs/zookeeper.json", optional: false, reloadOnChange: true);
#else
                build.AddCacheFile("${cachePath}|configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|configs/surgingSettings.json", optional: false, reloadOnChange: true);
                build.AddEventBusFile("${eventBusPath}|configs/eventBusSettings.json", optional: false);
                build.AddConsulFile("${consulPath}|configs/consul.json", optional: false, reloadOnChange: true);
                build.AddZookeeperFile("${zookeeperPath}|configs/zookeeper.json", optional: false, reloadOnChange: true);
#endif
            })
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()      //添加支持服务代理远程调用
                    .AddConfigurationWatch() //添加同步更新配置文件的监听处理
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    //.UseConsulManager(new ConfigInfo("127.0.0.1:8500"))//使用Consul管理
                    .AddServiceEngine(typeof(SurgingServiceEngine));
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));    //初始化注入容器
                });
            })
                       .ConfigureLogging(logger =>
            {
                logger.AddConfiguration(Surging.Core.CPlatform.AppConfig.GetSection("Logging"));
            })
                       .UseServer(options =>
            {
                //options.Ip = "127.0.0.1";
                //options.Port = 2801;
                //options.Token = "True";
                //options.ExecutionTimeoutInMilliseconds = 30000;
                //options.MaxConcurrentRequests = 200;
            })
                       //.UseLog4net("log4net.config") //使用log4net记录日志
                       //.UseLog4net(LogLevel.Error) //使用log4net记录日志
                       //.UseNLog(LogLevel.Error, "NLog.config")
                       .UseConsoleLifetime()
                       .UseLog4net()
                       .Configure(build => build.AddCacheFile("${cachepath}|cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build => build.AddCPlatformFile("${surgingpath}|surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseStartup <Startup>()
                       .Build();

            //在启动的时候吧连接字符串赋值
            SurgingtestContext.DbConnStr = Surging.Core.CPlatform.AppConfig.GetSection("ConnectionStrings").GetSection("MySqlStr").Value;
            SqlClient.ConnectionString   = Surging.Core.CPlatform.AppConfig.GetSection("ConnectionStrings").GetSection("MySqlStr").Value;
            using (host.Run())
            {
                Console.WriteLine($"Surging.TestDemo服务端启动成功,{DateTime.Now}");
            }
        }
Example #20
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddClient()
                    .AddCache();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .ConfigureLogging(logger =>
            {
                logger.AddConfiguration(
                    Core.CPlatform.AppConfig.GetSection("Logging"));
            })
                       .Configure(build => {
#if DEBUG
                build.AddCacheFile("${cachePath}|/app/configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|/app/configs/surgingSettings.json", optional: false, reloadOnChange: true);
                // build.AddEventBusFile("${eventBusPath}|/app/configs/eventBusSettings.json", optional: false);
#else
                build.AddCacheFile("${cachePath}|configs/cacheSettings.json", optional: false, reloadOnChange: true);
                build.AddCPlatformFile("${surgingPath}|configs/surgingSettings.json", optional: false, reloadOnChange: true);
                build.AddEventBusFile("configs/eventBusSettings.json", optional: false);
#endif
            })
                       .UseClient()
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                // Startup.Test(ServiceLocator.GetService<IServiceProxyFactory>());
                //Startup.TestRabbitMq(ServiceLocator.GetService<IServiceProxyFactory>());
                // Startup.TestForRoutePath(ServiceLocator.GetService<IServiceProxyProvider>());
                /// test Parallel
                //var connectionCount = 300000;
                //StartRequest(connectionCount);
                //Console.ReadLine();
            }
        }
Example #21
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                // builder.RegisterAssemblyModules();
                //这里写自己的注册
            })
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    option.AddRelateService();
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    //option.UseMessagePackCodec();
                    option.UseJsonCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseLog4net("Configs/log4net.config")
                       .UseServer(options =>
            {
                options.Ip    = "127.0.0.1";
                options.Port  = 10241;
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
            })
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.Title = "认证授权";
                Console.WriteLine($"认证授权——服务端启动成功,{DateTime.Now}。");
                Console.ReadLine();
            }
        }
Example #22
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .AddServiceEngine(typeof(SurgingServiceEngine));
                    //option.UseConsulManager(new ConfigInfo("192.168.1.224:32769"));
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .ConfigureLogging(logger =>
            {
                logger.AddConfiguration(
                    Surging.Core.CPlatform.AppConfig.GetSection("Logging"));
            })
                       //.UseServer(options => { })
                       .UseServer(options =>
            {
                options.Ip    = "127.0.0.1";
                options.Port  = 9990;
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
                options.NotRelatedAssemblyFiles        = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*";
            })
                       .UseConsoleLifetime()
                       .Configure(build =>
                                  build.AddCacheFile("${cachepath}|cacheSettings.json", basePath: AppContext.BaseDirectory, optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("${surgingpath}|surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #23
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime();
                    option.AddRelateService();
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
                    option.UseDotNettyTransport();
                    option.UseRabbitMQTransport();
                    option.AddRabbitMQAdapt();
                    //option.UseProtoBufferCodec();
                    option.UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .UseLog4net("Configs/log4net.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options => {
                options.Ip    = "127.0.0.1";
                options.Port  = 98;
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 200;
            })
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #24
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseRabbitMQTransport()
                    .AddRabbitMQAdapt()
                    .AddCache()
                    .AddHttpProtocol()
                    .AddServiceEngine(typeof(SurgingServiceEngine));
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       .SubscribeAt()
                       .ConfigureLogging(logger =>
            {
                logger.AddConfiguration(
                    Core.CPlatform.AppConfig.GetSection("Logging"));
            })
                       .UseServer(options => { })
                       .UseConsoleLifetime()
                       .UseServiceCache()
                       .Configure(build =>
                                  build.AddCacheFile("${cachepath}|cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformFile("${surgingpath}|surgingSettings.json", optional: false, reloadOnChange: true))
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
        }
Example #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Server, Hello World!");

            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.RegisterType <MessagePackTransportMessageCodecFactory>().As <ITransportMessageCodecFactory>().SingleInstance();
                builder.RegisterType(typeof(HttpServiceExecutor)).As(typeof(IServiceExecutor)).Named <IServiceExecutor>("tcp").SingleInstance();
                builder.Register(provider =>
                {
                    return(new DotNettyServerMessageListener(provider.Resolve <ILogger <DotNettyServerMessageListener> >(),
                                                             provider.Resolve <ITransportMessageCodecFactory>()));
                }).SingleInstance();
                builder.Register(provider =>
                {
                    var serviceExecutor = provider.ResolveKeyed <IServiceExecutor>("tcp");
                    var messageListener = provider.Resolve <DotNettyServerMessageListener>();
                    return(new DotNettyTransportHost(async endPoint =>
                    {
                        await messageListener.StartAsync(endPoint);
                        return messageListener;
                    }, serviceExecutor));
                }).As <ITransportHost>();
            })
                       .UseServer() // 指定监听的端口
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }

            Console.ReadLine();
        }
Example #26
0
        static void Main(string[] args)
        {
            string consul           = ConfigHelper.AllConfigInfo["ConsulSettings"]["IpAddrs"].ToString();
            string Token            = ConfigHelper.AllConfigInfo["ConsulSettings"]["Token"].ToString();
            JToken RebbitMqSettings = ConfigHelper.AllConfigInfo["RebbitMqSettings"];
            JToken HostSettings     = ConfigHelper.AllConfigInfo["HostSettings"];
            //public ConfigInfo(string connectionString,
            //    string routePath = "services/serviceRoutes/", string subscriberPath = "services/serviceSubscribers/",
            //    string commandPath = "services/serviceCommands/", string cachePath = "services/serviceCaches/", bool reloadOnChange = false);
            //var config = new ConfigInfo(consul, "TEST/serviceRoutes/", "TEST/serviceSubscribers/",
            //    "TEST/serviceCommands/", "TEST/serviceCaches/",
            //    reloadOnChange: true);
            var config = new ConfigInfo(consul, reloadOnChange: true);

            config.Token = Token;
            //  JToken ORMSettings = ConfigHelper.AllConfigInfo["ORMSettings"];
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseConsulManager(config)
                    .UseDotNettyTransport()
                    //.UseRabbitMQTransport()
                    //.AddRabbitMQAdapt()

                    //.AddCache()
                    //.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //    kafkaOption.LogConnectionClose = false;
                    //    kafkaOption.MaxQueueBuffering = 10;
                    //    kafkaOption.MaxSocketBlocking = 10;
                    //    kafkaOption.EnableAutoCommit = false;
                    //})
                    //.AddKafkaMQAdapt()
                    //.UseProtoBufferCodec()
                    .UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       // .SubscribeAt()
                       .UseLog4net(LogLevel.Error, "Config/log4net.config")
                       // .UseNLog(LogLevel.Error, "Config/NLog.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options =>
            {
                //  options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);
                // options.Port = 10098;
                // options.Ip = "127.0.0.1";
                //options.Token
                options.Token = "123456789";
                options.ExecutionTimeoutInMilliseconds = 30000;
                options.MaxConcurrentRequests          = 2000;
            })
                       // .UseServiceCache()
                       //.Configure(build =>
                       //build.AddEventBusJson(RebbitMqSettings))
                       //.Configure(build =>
                       //build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformJSON(HostSettings))
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();


            //var list = JsonHelper.Deserialize<List<KaSon.FrameWork.ORM.OrmConfigInfo>>(ORMSettings.ToString());
            //DbProvider.InitConfigJson(list);

            using (host.Run())
            {
                #region 初始化配置
                InitConfigInfo.logFactory = ServiceLocator.GetService <ILoggerFactory>();

                #endregion
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            }
            Console.ReadKey();
        }
Example #27
0
        static void Main(string[] args)
        {
            string consul = ConfigHelper.AllConfigInfo["ConsulSettings"]["IpAddrs"].ToString();
            string Token  = ConfigHelper.AllConfigInfo["ConsulSettings"]["Token"].ToString();

            JToken RebbitMqSettings        = ConfigHelper.AllConfigInfo["RebbitMqSettings"];
            JToken HostSettings            = ConfigHelper.AllConfigInfo["HostSettings"];
            string Sports_SchemeJobSeconds = ConfigHelper.AllConfigInfo["Sports_SchemeJobSeconds"].ToString();
            var    config = new ConfigInfo(consul, reloadOnChange: true);

            config.Token = Token;
            //JToken ORMSettings = ConfigHelper.AllConfigInfo["ORMSettings"];
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       // .CaptureStartupErrors(true),
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseConsulManager(config)
                    .UseDotNettyTransport()
                    //.UseRabbitMQTransport()
                    //.AddRabbitMQAdapt()

                    // .AddCache()
                    //.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //    kafkaOption.LogConnectionClose = false;
                    //    kafkaOption.MaxQueueBuffering = 10;
                    //    kafkaOption.MaxSocketBlocking = 10;
                    //    kafkaOption.EnableAutoCommit = false;
                    //})
                    //.AddKafkaMQAdapt()
                    //.UseProtoBufferCodec()
                    .UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       //.SubscribeAt()
                       // .UseLog4net(LogLevel.Error, "Config/log4net.config")
                       // .UseNLog(LogLevel.Error, "Config/NLog.config")
                       .UseLog4net("Config/log4net.config")

                       .UseServer(options =>
            {
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;

                options.MaxConcurrentRequests = 2000;
            })
                       // .UseServiceCache()
                       //.Configure(build =>
                       //build.AddEventBusJson(RebbitMqSettings))
                       .Configure(build =>
                       //build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       //  .Configure(build =>
                                  build.AddCPlatformJSON(HostSettings))
                       .UseProxy()
                       .UseStartup <Startup>()
                       .Build();



            //var list = JsonHelper.Deserialize<List<KaSon.FrameWork.ORM.OrmConfigInfo>>(ORMSettings.ToString());
            //DbProvider.InitConfigJson(list);

            // InitConfigInfo.logFactory = ServiceLocator.GetService<ILoggerProvider>();



            using (host.Run())
            {
                #region 初始化配置
                InitConfigInfo.logFactory = ServiceLocator.GetService <ILoggerFactory>();

                #endregion

                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
                AutoTaskServices.AutoCaheData(int.Parse(Sports_SchemeJobSeconds));
            }
            //初始化内存期号 k_todo,可用彩种类型,执行一次
            LotteryGameManager lotGm = new LotteryGameManager();
            lotGm.StartInitData();
            //清空打印
            ConsoleHelper.Clear();
            //这个要保留,认主线程一直运行
            Console.ReadLine();
        }
Example #28
0
        static void Main(string[] args)
        {
            string consul = ConfigHelper.AllConfigInfo["ConsulSettings"]["IpAddrs"].ToString();

            JToken CrawSettings = ConfigHelper.AllConfigInfo["CrawSettings"];

            JToken RebbitMqSettings     = ConfigHelper.AllConfigInfo["RebbitMqSettings"];
            JToken HostSettings         = ConfigHelper.AllConfigInfo["HostSettings"];
            JToken MongoSettings        = ConfigHelper.AllConfigInfo["MongoSettings"];
            JToken BonusPoolSetting     = ConfigHelper.AllConfigInfo["BonusPoolSetting"];
            JToken Auto_CollectSettings = ConfigHelper.AllConfigInfo["Auto_CollectSettings"];

            string Sports_SchemeJobSeconds = ConfigHelper.AllConfigInfo["Sports_SchemeJobSeconds"].ToString();
            var    mongoConfig             = new kason.Sg.Core.Mongo.ConfigInfo();

            mongoConfig.connectionString = MongoSettings["connectionString"].ToString();
            mongoConfig.SingleInstance   = bool.Parse(MongoSettings["SingleInstance"].ToString());
            mongoConfig.dbName           = MongoSettings["dbName"].ToString();

            //初始化数据
            Lottery.CrawGetters.InitConfigInfo.MongoSettings = MongoSettings;

            Lottery.CrawGetters.InitConfigInfo.MongoTableSettings = MongoSettings["TableNamesSettings"];
            Lottery.CrawGetters.InitConfigInfo.BonusPoolSetting   = CrawSettings["BonusPoolSettings"];
            Lottery.CrawGetters.InitConfigInfo.MatchSettings      = CrawSettings["MatchSettings"];
            ServiceHelper.MatchSettings = CrawSettings["MatchSettings"];
            Lottery.CrawGetters.InitConfigInfo.NumLettory_SleepTimeSpanSettings = CrawSettings["NumLettory_SleepTimeSpanSettings"];

            //JToken ORMSettings = ConfigHelper.AllConfigInfo["ORMSettings"];
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.AddMicroService(option =>
                {
                    option.AddServiceRuntime()
                    .UseMongo(mongoConfig)
                    .AddRelateService()
                    .AddConfigurationWatch()
                    //option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
                    .UseConsulManager(new Kason.Sg.Core.Consul.Configurations.ConfigInfo(consul,
                                                                                         "MagAndCraw/serviceRoutes/",
                                                                                         "MagAndCraw/serviceSubscribers/",
                                                                                         "MagAndCraw/serviceCommands/",
                                                                                         "MagAndCraw/serviceCaches/")
                    {
                        ReloadOnChange = true
                    })
                    .UseDotNettyTransport()
                    //.UseRabbitMQTransport()
                    // .AddRabbitMQAdapt()

                    // .AddCache()
                    //.UseKafkaMQTransport(kafkaOption =>
                    //{
                    //    kafkaOption.Servers = "127.0.0.1";
                    //    kafkaOption.LogConnectionClose = false;
                    //    kafkaOption.MaxQueueBuffering = 10;
                    //    kafkaOption.MaxSocketBlocking = 10;
                    //    kafkaOption.EnableAutoCommit = false;
                    //})
                    //.AddKafkaMQAdapt()
                    //.UseProtoBufferCodec()
                    .UseMessagePackCodec();
                    builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
                });
            })
                       // .SubscribeAt()
                       // .UseLog4net(LogLevel.Error, "Config/log4net.config")
                       // .UseNLog(LogLevel.Error, "Config/NLog.config")
                       .UseLog4net("Config/log4net.config")
                       //.UseServer("127.0.0.1", 98)
                       //.UseServer("127.0.0.1", 98,“true”) //自动生成Token
                       //.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
                       .UseServer(options =>
            {
                //  options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);
                // options.Port = 10098;
                // options.Ip = "127.0.0.1";
                options.Token = "True";
                options.ExecutionTimeoutInMilliseconds = 30000;

                options.MaxConcurrentRequests = 2000;
            })
                       // .UseServiceCache()
                       //.Configure(build =>
                       //build.AddEventBusJson(RebbitMqSettings))
                       //.Configure(build =>
                       //build.AddCacheFile("cacheSettings.json", optional: false, reloadOnChange: true))
                       .Configure(build =>
                                  build.AddCPlatformJSON(HostSettings))
                       // .UseProxy()
                       .UseStartup <Startup>()
                       .Build();

            //string url = "https://1680660.com/smallSix/queryLotteryDate.do?ym=2019-04";
            //var list= Lottery.CrawGetters.WinNumberGetter_1680660.GetIssuseNum();

            //Console.WriteLine(string.Join(Environment.NewLine, list));
            //var list = JsonHelper.Deserialize<List<KaSon.FrameWork.ORM.OrmConfigInfo>>(ORMSettings.ToString());
            //DbProvider.InitConfigJson(list);

            //WinNumberGetter_1680660.winNum();

            using (host.Run())
            {
                Console.WriteLine($"管理、采集,开奖服务端启动成功,{DateTime.Now}。");
                Lottery.CrawGetters.InitConfigInfo.Init(CrawSettings);
                Lottery.CrawGetters.InitConfigInfo.logFactory    = ServiceLocator.GetService <ILoggerFactory>();
                KaSon.FrameWork.Common.InitConfigInfo.logFactory = ServiceLocator.GetService <ILoggerFactory>();
                //AutoTaskServices.AutoCaheData(int.Parse(Sports_SchemeJobSeconds));
            }
            // 初始化内存期号 k_todo,可用彩种类型,执行一次
            // LotteryGameManager lotGm = new LotteryGameManager();
            // lotGm.StartInitData();
            //new Sports_Business().Test();



            Task.Factory.StartNew(async delegate
            {
                var obj = await Start_ConfigGameType(Auto_CollectSettings);
            });
            //RedisMatchBusiness.ReloadCurrentBJDCMatch();
            Clear();
        }