如何使用代码配置而不是 XML 文件配置启动服务器?
How can I start the server with the code configuration rather than the XML file configuration?
我想用代码配置而不是XML文件配置来启动服务器,但是如果不调用LoadOrleansConfig方法,silo服务器就无法启动。
string providerName = "MySql.Data.MySqlClient";
string mysqlConnString = "mysqlConnString";
var config = new ClusterConfiguration();
config.Globals.DeploymentId = "OrleansTest";
config.Globals.AdoInvariant = providerName;
config.Globals.DataConnectionString = mysqlConnString;
config.Globals.LivenessType = LivenessProviderType.Custom;
config.Globals.ReminderServiceType = ReminderServiceProviderType.Custom;
config.Globals.MembershipTableAssembly = "OrleansSQLUtils";
config.Globals.ReminderTableAssembly = "OrleansSQLUtils";
config.Defaults.HostNameOrIPAddress = "localhost";
config.Defaults.Port = 11111;
config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, 30000);
using (var host = new SiloHost("Default"))
{
host.Config = config;
host.InitializeOrleansSilo();
var result = host.StartOrleansSilo();
Console.WriteLine("server startup {0}", result ? "successful" : "failure");
Console.ReadLine();
host.StopOrleansSilo();
}
您不必从文件加载配置。
而不是 host.Config = config;
通过构造函数传递配置:
https://github.com/dotnet/orleans/blob/master/src/OrleansRuntime/Silo/SiloHost.cs#L97
默认情况下,启动筒仓将吞下任何异常。像这样开始,你会得到更多信息:
var result = host.StartOrleansSilo(catchExceptions: false);
在这种情况下,你得到:
"Cannot start silo Default due to prior initialization error"
这不是你不知道的。要解决此问题,请像这样设置您的 SiloHost:
using (var host = new SiloHost("Default", config))
我想用代码配置而不是XML文件配置来启动服务器,但是如果不调用LoadOrleansConfig方法,silo服务器就无法启动。
string providerName = "MySql.Data.MySqlClient";
string mysqlConnString = "mysqlConnString";
var config = new ClusterConfiguration();
config.Globals.DeploymentId = "OrleansTest";
config.Globals.AdoInvariant = providerName;
config.Globals.DataConnectionString = mysqlConnString;
config.Globals.LivenessType = LivenessProviderType.Custom;
config.Globals.ReminderServiceType = ReminderServiceProviderType.Custom;
config.Globals.MembershipTableAssembly = "OrleansSQLUtils";
config.Globals.ReminderTableAssembly = "OrleansSQLUtils";
config.Defaults.HostNameOrIPAddress = "localhost";
config.Defaults.Port = 11111;
config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, 30000);
using (var host = new SiloHost("Default"))
{
host.Config = config;
host.InitializeOrleansSilo();
var result = host.StartOrleansSilo();
Console.WriteLine("server startup {0}", result ? "successful" : "failure");
Console.ReadLine();
host.StopOrleansSilo();
}
您不必从文件加载配置。
而不是 host.Config = config;
通过构造函数传递配置:
https://github.com/dotnet/orleans/blob/master/src/OrleansRuntime/Silo/SiloHost.cs#L97
默认情况下,启动筒仓将吞下任何异常。像这样开始,你会得到更多信息:
var result = host.StartOrleansSilo(catchExceptions: false);
在这种情况下,你得到:
"Cannot start silo Default due to prior initialization error"
这不是你不知道的。要解决此问题,请像这样设置您的 SiloHost:
using (var host = new SiloHost("Default", config))