static void Main(string[] args) { if (args.Length == 0) { var cfgList = new List <RuntimeConfig>(); var obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17777; //auto obj.AppName = "Login.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "LoginService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17778; //auto obj.AppName = "Match.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MatchService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17779; //auto obj.AppName = "Master.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MasterService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17780; //auto obj.AppName = "Zone.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "ZoneService" }; cfgList.Add(obj); using (var sw = new StreamWriter("app.json", false, Encoding.UTF8)) { var content = JsonConvert.SerializeObject(cfgList, Formatting.Indented); sw.Write(content); } Environment.SetEnvironmentVariable("AppName", "Login.App"); //Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly}, cfgList, OnInit, isMultiProcess:true); //单进程模式 Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: false); //单进程模式 } else { var builder = new ConfigurationBuilder().AddCommandLine(args); var cmdLine = builder.Build(); //将命令行参数,设置到进程的环境变量 Environment.SetEnvironmentVariable("AppName", cmdLine["AppName"]); using (var sr = new StreamReader(cmdLine["Config"])) { var cfgList = JsonConvert.DeserializeObject <List <RuntimeConfig> >(sr.ReadToEnd()); Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true); //分布式 } } }
static void Main(string[] args) { StaticCompositeResolver.Instance.Register( MessagePack.Resolvers.ClientAppResolver.Instance, MessagePack.Resolvers.FenixRuntimeResolver.Instance, MessagePack.Resolvers.SharedResolver.Instance, MessagePack.Unity.UnityResolver.Instance, MessagePack.Unity.Extension.UnityBlitResolver.Instance, MessagePack.Unity.Extension.UnityBlitWithPrimitiveArrayResolver.Instance, MessagePack.Resolvers.AttributeFormatterResolver.Instance, MessagePack.Resolvers.BuiltinResolver.Instance, MessagePack.Resolvers.StandardResolver.Instance ); if (args.Length == 0) { var cfgList = new List <RuntimeConfig>(); var obj = new RuntimeConfig(); obj.ExternalIP = "auto"; obj.InternalIP = "0.0.0.0"; obj.Port = 17777; //auto obj.AppName = "Login.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "LoginService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIP = "auto"; obj.InternalIP = "0.0.0.0"; obj.Port = 17778; //auto obj.AppName = "Match.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MatchService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIP = "auto"; obj.InternalIP = "0.0.0.0"; obj.Port = 17779; //auto obj.AppName = "Master.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MasterService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIP = "auto"; obj.InternalIP = "0.0.0.0"; obj.Port = 17780; //auto obj.AppName = "Zone.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "ZoneService" }; cfgList.Add(obj); using (var sw = new StreamWriter("app.json", false, Encoding.UTF8)) { var content = JsonConvert.SerializeObject(cfgList, Formatting.Indented); sw.Write(content); } //for Debug purpose Environment.SetEnvironmentVariable("AppPath", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../")); Bootstrap.StartSingleProcess(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit); //单进程模式 // foreach (var cfg in cfgList) // if (cfg.AppName == "Login.App") // Bootstrap.StartMultiProcess(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfg, OnInit); //分布式 } else { Environment.SetEnvironmentVariable("AppPath", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../")); Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { Environment.SetEnvironmentVariable("AppName", o.AppName); using (var sr = new StreamReader(o.Config)) { var cfgList = JsonConvert.DeserializeObject <List <RuntimeConfig> >(sr.ReadToEnd()); foreach (var cfg in cfgList) { if (cfg.AppName == o.AppName) { Bootstrap.StartMultiProcess(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfg, OnInit); } } } }); } }
static void Main(string[] args) { StaticCompositeResolver.Instance.Register( MessagePack.Resolvers.ClientAppResolver.Instance, MessagePack.Resolvers.FenixRuntimeResolver.Instance, MessagePack.Resolvers.SharedResolver.Instance, MessagePack.Unity.UnityResolver.Instance, MessagePack.Unity.Extension.UnityBlitResolver.Instance, MessagePack.Unity.Extension.UnityBlitWithPrimitiveArrayResolver.Instance, MessagePack.Resolvers.StandardResolver.Instance ); if (args.Length == 0) { var cfgList = new List <RuntimeConfig>(); var obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17777; //auto obj.AppName = "Login.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "LoginService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17778; //auto obj.AppName = "Match.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MatchService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17779; //auto obj.AppName = "Master.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "MasterService" }; cfgList.Add(obj); obj = new RuntimeConfig(); obj.ExternalIp = "auto"; obj.InternalIp = "auto"; obj.Port = 17780; //auto obj.AppName = "Zone.App"; obj.HeartbeatIntervalMS = 5000; obj.ClientNetwork = NetworkType.TCP; obj.DefaultActorNames = new List <string>() { "ZoneService" }; cfgList.Add(obj); using (var sw = new StreamWriter("app.json", false, Encoding.UTF8)) { var content = JsonConvert.SerializeObject(cfgList, Formatting.Indented); sw.Write(content); } Environment.SetEnvironmentVariable("AppName", "Login.App"); Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true); //单进程模式 //Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: false); //单进程模式 } else { Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { //将命令行参数,设置到进程的环境变量 Environment.SetEnvironmentVariable("AppName", o.AppName); using (var sr = new StreamReader(o.Config)) { var cfgList = JsonConvert.DeserializeObject <List <RuntimeConfig> >(sr.ReadToEnd()); Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true); //分布式 } }); } }