message.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Code generated by goctl. DO NOT EDIT!
  2. // Source: message.proto
  3. package main
  4. import (
  5. "app.yhyue.com/moapp/MessageCenter/entity"
  6. "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
  7. "app.yhyue.com/moapp/MessageCenter/rpc/internal/server"
  8. "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
  9. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  10. m "app.yhyue.com/moapp/jybase/mongodb"
  11. "app.yhyue.com/moapp/jybase/mysql"
  12. "app.yhyue.com/moapp/jybase/redis"
  13. "flag"
  14. "fmt"
  15. "github.com/zeromicro/go-zero/core/conf"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. "github.com/zeromicro/go-zero/zrpc"
  18. "google.golang.org/grpc"
  19. "log"
  20. )
  21. var configFile = flag.String("f", "etc/message.yaml", "the config file")
  22. var logFile = flag.String("lf", "etc/logs.yaml", "the logs file")
  23. var logc entity.Logc
  24. var c config.Config
  25. func main() {
  26. flag.Parse()
  27. conf.MustLoad(*configFile, &c)
  28. ctx := svc.NewServiceContext(c)
  29. srv := server.NewMessageServer(ctx)
  30. s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  31. message.RegisterMessageServer(grpcServer, srv)
  32. })
  33. defer s.Stop()
  34. fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
  35. s.Start()
  36. }
  37. // 创建orm引擎
  38. func init() {
  39. conf.MustLoad(*configFile, &config.ConfigJson)
  40. log.Println("开始初始化数据库。。。。。")
  41. //初始化mysql
  42. entity.Mysql = &mysql.Mysql{
  43. Address: config.ConfigJson.DataSource.Address,
  44. UserName: config.ConfigJson.DataSource.UserName,
  45. PassWord: config.ConfigJson.DataSource.PassWord,
  46. DBName: config.ConfigJson.DataSource.DbName,
  47. MaxOpenConns: config.ConfigJson.DataSource.MaxOpenConns,
  48. MaxIdleConns: config.ConfigJson.DataSource.MaxIdleConns,
  49. }
  50. entity.Mysql.Init()
  51. data := entity.Mysql.Find("message_column", map[string]interface{}{"equity": "message_center"}, "", "sequence", -1, -1)
  52. if data != nil && len(*data) > 0 {
  53. entity.MessageColumn = *data
  54. }
  55. //初始化basemysql
  56. entity.BaseMysql = &mysql.Mysql{
  57. Address: config.ConfigJson.BaseSource.Address,
  58. UserName: config.ConfigJson.BaseSource.UserName,
  59. PassWord: config.ConfigJson.BaseSource.PassWord,
  60. DBName: config.ConfigJson.BaseSource.DbName,
  61. MaxOpenConns: config.ConfigJson.BaseSource.MaxOpenConns,
  62. MaxIdleConns: config.ConfigJson.BaseSource.MaxIdleConns,
  63. }
  64. entity.BaseMysql.Init()
  65. //初始化 redis
  66. if config.ConfigJson.Redis.Addr != "" {
  67. if config.ConfigJson.Redis.Modules == "" {
  68. config.ConfigJson.Redis.Modules = "other"
  69. }
  70. log.Println("--初始化 redis--")
  71. redis.InitRedisBySize(fmt.Sprintf("%s=%s", config.ConfigJson.Redis.Modules, config.ConfigJson.Redis.Addr), 20, 30, 300)
  72. }
  73. // 初始化mongo
  74. if config.ConfigJson.Mongodb != nil {
  75. log.Println("初始化 mongodb main")
  76. entity.MQFW = m.MongodbSim{
  77. MongodbAddr: config.ConfigJson.Mongodb.Address,
  78. Size: config.ConfigJson.Mongodb.Size,
  79. DbName: config.ConfigJson.Mongodb.DbName,
  80. ReplSet: config.ConfigJson.Mongodb.ReplSet,
  81. }
  82. entity.MQFW.InitPool()
  83. }
  84. // 初始化消息保存并发通道
  85. entity.SaveConcurrencyChan = make(chan int, config.ConfigJson.SaveConcurrency)
  86. //初始化日志信息
  87. conf.MustLoad(*logFile, &logc)
  88. if len(logc.Level) > 0 {
  89. for _, v := range logc.Level {
  90. logx.MustSetup(logx.LogConf{
  91. Mode: logc.Mode,
  92. Path: logc.Path,
  93. Level: v,
  94. KeepDays: logc.KeepDays,
  95. })
  96. logx.Info(v, "--日志记录")
  97. }
  98. }
  99. if config.ConfigJson.SurvivalTime != 0 {
  100. entity.SurvivalTime = config.ConfigJson.SurvivalTime
  101. }
  102. }