You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcm.go 2.0 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "github.com/zeromicro/go-queue/kq"
  6. "github.com/zeromicro/go-zero/core/conf"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "github.com/zeromicro/go-zero/core/service"
  9. "github.com/zeromicro/go-zero/rest"
  10. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/config"
  11. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler"
  12. kqMq "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/mqs/kq"
  13. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  14. commonConfig "gitlink.org.cn/jcce-pcm/utils/nacos"
  15. )
  16. var configFile = flag.String("f", "api/etc/pcm.yaml", "the config file")
  17. func main() {
  18. flag.Parse()
  19. var bootstrapConfig commonConfig.BootstrapConfig
  20. conf.MustLoad(*configFile, &bootstrapConfig)
  21. //解析业务配置
  22. var c config.Config
  23. nacosConfig := bootstrapConfig.NacosConfig
  24. serviceConfigContent := nacosConfig.InitConfig(func(data string) {
  25. err := conf.LoadFromYamlBytes([]byte(data), &c)
  26. if err != nil {
  27. panic(err)
  28. }
  29. })
  30. err := conf.LoadFromYamlBytes([]byte(serviceConfigContent), &c)
  31. if err != nil {
  32. panic(err)
  33. }
  34. // 注册到nacos
  35. nacosConfig.DiscoveryRest(&c.RestConf)
  36. serviceGroup := service.NewServiceGroup()
  37. defer serviceGroup.Stop()
  38. server := rest.MustNewServer(c.RestConf, rest.WithCors())
  39. ctx := svc.NewServiceContext(c)
  40. // start log component
  41. logx.MustSetup(c.LogConf)
  42. ctx.Cron.Start()
  43. handler.RegisterHandlers(server, ctx)
  44. serviceGroup.Add(server)
  45. services := []service.Service{
  46. //Listening for changes in consumption flow status
  47. kq.MustNewQueue(c.HpcConsumerConf, kqMq.NewScheduleHpcMq(context.Background(), ctx)),
  48. kq.MustNewQueue(c.CloudConsumerConf, kqMq.NewScheduleCloudMq(context.Background(), ctx)),
  49. kq.MustNewQueue(c.AiConsumerConf, kqMq.NewScheduleAiMq(context.Background(), ctx)),
  50. //.....
  51. }
  52. for _, mq := range services {
  53. serviceGroup.Add(mq)
  54. }
  55. logx.Infof("Starting server at %s:%d...\n", c.Host, c.Port)
  56. serviceGroup.Start()
  57. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.