Dapr 源码解析 | 服务启动过程
- 在dapr源码项目中,从cmd/daprd/main.go 启动类入口进行启动过程分析
- 在main方法中,应用启动方法:func (a *DaprRuntime) Run(opts ...Option) error ,位于pkg/runtime/runtime文件中,其中入参 opts:表示dapr运行时实例的各种组件配置项,包括 SecretStores, States, Configurations, PubSubs, NameResolutions, InputBindings, OutputBindings, HTTPMiddleware 等配置
- Run方法启动过程:1) 解析启动配置项: runtimeOpts 2)启动初始化: initRuntime(&o)
- initRuntime方法执行过程中
4.1 以下方法负责 服务域名解析,即通过appId名称找到对应服务调用ip及port,在initNameResolution方法中包括了域名解析组件的初始化,及服务注册过程
// Register and initialize name resolution for service discovery.
a.nameResolutionRegistry.Register(opts.nameResolutions...)
err = a.initNameResolution()