123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- // Code generated by goctl. DO NOT EDIT!
- // Source: message.proto
- package main
- import (
- "app.yhyue.com/moapp/MessageCenter/entity"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/server"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
- "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
- m "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/mysql"
- "app.yhyue.com/moapp/jybase/redis"
- "flag"
- "fmt"
- "github.com/zeromicro/go-zero/core/conf"
- "github.com/zeromicro/go-zero/core/logx"
- "github.com/zeromicro/go-zero/zrpc"
- "google.golang.org/grpc"
- "log"
- )
- var configFile = flag.String("f", "etc/message.yaml", "the config file")
- var logFile = flag.String("lf", "etc/logs.yaml", "the logs file")
- var logc entity.Logc
- var c config.Config
- func main() {
- flag.Parse()
- conf.MustLoad(*configFile, &c)
- ctx := svc.NewServiceContext(c)
- srv := server.NewMessageServer(ctx)
- s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
- message.RegisterMessageServer(grpcServer, srv)
- })
- defer s.Stop()
- fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
- s.Start()
- }
- // 创建orm引擎
- func init() {
- conf.MustLoad(*configFile, &config.ConfigJson)
- log.Println("开始初始化数据库。。。。。")
- //初始化mysql
- entity.Mysql = &mysql.Mysql{
- Address: config.ConfigJson.DataSource.Address,
- UserName: config.ConfigJson.DataSource.UserName,
- PassWord: config.ConfigJson.DataSource.PassWord,
- DBName: config.ConfigJson.DataSource.DbName,
- MaxOpenConns: config.ConfigJson.DataSource.MaxOpenConns,
- MaxIdleConns: config.ConfigJson.DataSource.MaxIdleConns,
- }
- entity.Mysql.Init()
- data := entity.Mysql.Find("message_column", map[string]interface{}{"equity": "message_center"}, "", "sequence", -1, -1)
- if data != nil && len(*data) > 0 {
- entity.MessageColumn = *data
- }
- //初始化basemysql
- entity.BaseMysql = &mysql.Mysql{
- Address: config.ConfigJson.BaseSource.Address,
- UserName: config.ConfigJson.BaseSource.UserName,
- PassWord: config.ConfigJson.BaseSource.PassWord,
- DBName: config.ConfigJson.BaseSource.DbName,
- MaxOpenConns: config.ConfigJson.BaseSource.MaxOpenConns,
- MaxIdleConns: config.ConfigJson.BaseSource.MaxIdleConns,
- }
- entity.BaseMysql.Init()
- //初始化 redis
- if config.ConfigJson.Redis.Addr != "" {
- if config.ConfigJson.Redis.Modules == "" {
- config.ConfigJson.Redis.Modules = "other"
- }
- log.Println("--初始化 redis--")
- redis.InitRedisBySize(fmt.Sprintf("%s=%s", config.ConfigJson.Redis.Modules, config.ConfigJson.Redis.Addr), 20, 30, 300)
- }
- // 初始化mongo
- if config.ConfigJson.Mongodb != nil {
- log.Println("初始化 mongodb main")
- entity.MQFW = m.MongodbSim{
- MongodbAddr: config.ConfigJson.Mongodb.Address,
- Size: config.ConfigJson.Mongodb.Size,
- DbName: config.ConfigJson.Mongodb.DbName,
- ReplSet: config.ConfigJson.Mongodb.ReplSet,
- }
- entity.MQFW.InitPool()
- }
- // 初始化消息保存并发通道
- entity.SaveConcurrencyChan = make(chan int, config.ConfigJson.SaveConcurrency)
- //初始化日志信息
- conf.MustLoad(*logFile, &logc)
- if len(logc.Level) > 0 {
- for _, v := range logc.Level {
- logx.MustSetup(logx.LogConf{
- Mode: logc.Mode,
- Path: logc.Path,
- Level: v,
- KeepDays: logc.KeepDays,
- })
- logx.Info(v, "--日志记录")
- }
- }
- if config.ConfigJson.SurvivalTime != 0 {
- entity.SurvivalTime = config.ConfigJson.SurvivalTime
- }
- }
|