-
Notifications
You must be signed in to change notification settings - Fork 9
启动服务端
Owen edited this page Apr 26, 2019
·
8 revisions
Uragano支持Web Host,也支持Generic host
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddUragano(Configuration, builder =>
{
builder.AddServer();
builder.AddConsul();
});
}
var hostBuilder = new HostBuilder().ConfigureHostConfiguration(builder =>
{
builder.SetBasePath(Directory.GetCurrentDirectory());
}).ConfigureAppConfiguration((context, builder) =>
{
builder.AddJsonFile("uragano.json", false, true);
builder.AddCommandLine(args);
})
.ConfigureServices((context, service) =>
{
service.AddUragano(context.Configuration, builder =>
{
builder.AddServer();
builder.AddConsul();
});
}).ConfigureLogging((context, builder) =>
{
builder.AddConfiguration(context.Configuration.GetSection("Logging"));
builder.AddConsole();
});
await hostBuilder.RunConsoleAsync();
AddServer,AddConsul这两个方法都提供多种重载
"Uragano": {
"Server": {
"address": "{LOCALIP}",
"port": 5002,
"weight": 1,
"certUrl": "",
"certPwd": "",
},
"ServiceDiscovery": {
"Consul": {
"Client": {
"Address": "http://localhost:8500"
},
"Service": {
"Id": null,
"Name": "RPC",
"tags": null,
"EnableTagOverride": false,
"meta": null,
"HealthCheckInterval": 10
}
}
}
}
Server 部分是我们的RPC服务的服务器配置,监听地址和端口号,{LOCALIP}表示使用当前服务器的局域网IP,weight是当前服务节点的权重,主要用于负载算法;certUrl,certPwd是启用Tls的证书配置,如果启用了Tls,对应的客户端也需要配置证书,并且同一组服务(服务注册与发现Name相同)必须使用同一套证书。
ServiceDiscovery:Consul 部分是Consul相关的配置,需要注意的是:
1.id是注册服务的唯一id,不配置或者是null的话系统会自动以服务的{IP}:{Port}作为服务id。
2.Name是向Consul里注册的服务名称,需要跟刚才申明的服务接口里的ServiceDiscoveryName属性定义的名称一致。
运行项目即可启动服务。