Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置文件 #54

Open
deshengchen opened this issue Dec 30, 2020 · 2 comments
Open

配置文件 #54

deshengchen opened this issue Dec 30, 2020 · 2 comments

Comments

@deshengchen
Copy link

作者您好,刚学习这个作品,在使用前期遇到一些问题,请作者指点。

1、在master-node的appconfig中配置了port,启动后仍是30000端口。是否是因为启动代码中使用了固定30000端口?如要在配置文件中获取端口,需做什么修改?

源码:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
webBuilder.UseUrls("http://*:30000");
})

2、work-node配置文件中配置了port,为何启动时要带参数urls来限定端口?

文档说明:
dotnet Hos.ScheduleMaster.QuartzHost.dll --urls http://*:30001

3、直接执行dotnet Hos.ScheduleMaster.QuartzHost.dll,使用了随机端口,如何使用配置文件中的port?

命令行:
E:\publish\ScheduleMaster\Worker1>dotnet Hos.ScheduleMaster.QuartzHost.dll
Security Warning: The negotiated TLS 1.0 is an insecure protocol and is supported for backward compa
tibility only. The recommended protocol version is TLS 1.2 and later.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Hos.ScheduleMaster.QuartzHost.AppStart.AppLifetimeHostedService[0]
Hosted service OnStarted
info: Hos.ScheduleMaster.QuartzHost.AppStart.AppLifetimeHostedService[0]
enabled auto register...
info: Hos.ScheduleMaster.QuartzHost.AppStart.ConfigurationRefreshService[0]
ConfigurationRefresh Finished.
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: E:\publish\ScheduleMaster\Worker1
info: Hos.ScheduleMaster.QuartzHost.AppStart.ConfigurationRefreshService[0]
ConfigurationRefresh Finished.

@hey-hoho
Copy link
Owner

感谢您的关注。

1、配置文件中的port参数只是为了节点注册时指出当前服务所在的端口号,方便节点间互相通信,并不是限制了服务启动的端口,这一点master和worker都是一样的,配置文件中的port参数必须对应服务实际启动的端口,这点非常重要。master被设计成单实例运行,所以固定端口就是30000在程序中写死了,如果要修改就把配置文件和源码一起修改即可。

2、worker被设计成多实例运行,意味着可以通过多个不同端口启动多个worker实例,所以启动端口不宜固定,启动时通过--urls参数动态指定,如果不指定这个参数,ASP.NET Core框架会默认使用5000端口(http)和5001端口(https)。

3、如第2条所述,另外目前不支持从配置文件读取启动端口。

@Harryguo2020
Copy link

可以通过修改 ConfigureWebHostDefaults 实现从配置文件加载端口的需求,
代码如下
public static IHostBuilder CreateHostBuilder(string[] args) =>
Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var config = builder.Build();
var port = config["NodeSetting:Port"];
webBuilder.UseUrls($"http://*:{port}").UseStartup();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants