当前位置: 首页 > news >正文

【Temporal】Server启动逻辑

Server启动

代码入口:temporal/cmd/server/main.go

       Choose here       javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql     

s, err := temporal.NewServer(temporal.ForServices(services),temporal.WithConfig(cfg),temporal.WithDynamicConfigClient(dynamicConfigClient),temporal.WithLogger(logger),temporal.InterruptOn(temporal.InterruptCh()),temporal.WithAuthorizer(authorizer),temporal.WithClaimMapper(func(cfg *config.Config) authorization.ClaimMapper {return claimMapper}),
)
if err != nil {return cli.Exit(fmt.Sprintf("Unable to create server. Error: %v.", err), 1)
}err = s.Start()
func (s *ServerFx) Start() error {err := s.app.Start(context.Background())if err != nil {return err}......return nil
}

通过上面可以看到sever是通过一个app实例来启动的,那么这个app是什么呢?
我们找到这个app初始化的地方:

func NewServerFx(topLevelModule fx.Option, opts ...ServerOption) (*ServerFx, error) {var s ServerFxs.app = fx.New(topLevelModule,fx.Supply(opts),fx.Populate(&s.startupSynchronizationMode),fx.Populate(&s.logger),)if err := s.app.Err(); err != nil {return nil, err}return &s, nil
}

可以看到,这个app实际上一个fx实例,这个fx是一个uber开源的库,这个库是golang中非常流行的依赖注入解决方案库,具体后面有时间再单独拿出来讲解。

模块启动逻辑

这里我们主要来看下server启动的时候加载了哪些模块,我们找到topLevelModule:

TopLevelModule = fx.Options(pprof.Module,fx.Provide(NewServerFxImpl),fx.Provide(ServerOptionsProvider),TraceExportModule,fx.Provide(PersistenceFactoryProvider),fx.Provide(HistoryServiceProvider),fx.Provide(MatchingServiceProvider),fx.Provide(FrontendServiceProvider),fx.Provide(InternalFrontendServiceProvider),fx.Provide(WorkerServiceProvider),fx.Provide(ApplyClusterMetadataConfigProvider),fx.Invoke(ServerLifetimeHooks),FxLogAdapter,
)

通过对fix的了解我们知道,fx.invoke()方法就是执行一些模块的启动逻辑,相当于我们写的init()方法,在服务启动的时候自动执行,所以我们可以通过全局搜索fx.invoke来找到temporal server启动的时候都做了些什么。


http://www.mrgr.cn/news/4222.html

相关文章:

  • 数据库MySQL多表设计、查询
  • 【Redis】如何从单机架构演化为分布式系统
  • 【Java日志系列】Logback日志框架
  • ⌈ 传知代码 ⌋ DETR[端到端目标检测]
  • Metasploit漏洞利用系列(八):MSF渗透测试 - PHPCGI漏洞利用实战
  • 基于PHP+MySQL组合开发的DIY分销商城小程序源码系统 附带源代码包以及搭建部署教程
  • hyperf 协程作用和相关的方法
  • 通配符证书:轻松管理您的子域名安全
  • Git基础使用
  • NO呼气检测在临床应用重要性
  • HTTP请求的流转路径,从Tomcat到SpringMVC
  • Linux: 忘记密码的解决方法,passwd
  • EmguCV学习笔记 VB.Net 4.1 颜色变换
  • C++模板方法TemplateMethod
  • JavaScript AI 编程助手
  • 关于开源许可协议
  • JAVA中的ByteArrayInputStream
  • CentOS服务器三级等保加固
  • Spring Data Reactive的使用和介绍
  • Oracle从入门到项目实践