上传跨服服务列表同步接口
This commit is contained in:
parent
20f1957623
commit
257860e5f5
@ -235,6 +235,8 @@ const ( //Rpc
|
||||
Rpc_ModulePayDelivery core.Rpc_Key = "Rpc_ModulePayDelivery" //充值发货
|
||||
// 配置更新
|
||||
Rpc_ConfigureUpDate core.Rpc_Key = "Rpc_ConfigureUpDate" //配置更新
|
||||
// 配置更新
|
||||
Rpc_DBSyncCross core.Rpc_Key = "Rpc_DBSyncCross" //同步区服列表 只有跨服服务器使用
|
||||
// 羁绊信息
|
||||
Rpc_ModuleFetter core.Rpc_Key = "Rpc_ModuleFetter"
|
||||
|
||||
|
64
modules/web/api_synccross.go
Normal file
64
modules/web/api_synccross.go
Normal file
@ -0,0 +1,64 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/gin"
|
||||
"go_dreamfactory/lego/sys/gin/engine"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SyncCrossReq struct {
|
||||
Timestamp string `json:"timestamp"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
type SyncCrossResp struct {
|
||||
Code int32 `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
//同步跨服列表
|
||||
func (this *Api_Comp) SyncCross(c *engine.Context) {
|
||||
var (
|
||||
req *SyncCrossReq = &SyncCrossReq{}
|
||||
resp *SyncCrossResp = &SyncCrossResp{}
|
||||
err error
|
||||
)
|
||||
defer c.JSON(http.StatusOK, resp)
|
||||
if err = c.BindJSON(req); err != nil {
|
||||
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
||||
resp.Message = pb.GetErrorCodeMsg(pb.ErrorCode_ReqParameterError)
|
||||
return
|
||||
}
|
||||
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{
|
||||
"timestamp": req.Timestamp,
|
||||
}); sign != req.Sign {
|
||||
this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
||||
resp.Code = int32(pb.ErrorCode_SignError)
|
||||
resp.Message = pb.GetErrorCodeMsg(pb.ErrorCode_SignError)
|
||||
return
|
||||
}
|
||||
if !db.IsCross() {
|
||||
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
||||
resp.Message = "curr service is not cross!"
|
||||
return
|
||||
}
|
||||
if err = db.SyncServiceList(); err != nil {
|
||||
resp.Code = int32(pb.ErrorCode_ReqParameterError)
|
||||
resp.Message = err.Error()
|
||||
return
|
||||
}
|
||||
if err = this.module.service.RpcBroadcast(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_DBSyncCross),
|
||||
pb.EmptyReq{},
|
||||
pb.EmptyResp{}); err != nil {
|
||||
this.module.Errorln(err)
|
||||
resp.Code = int32(pb.ErrorCode_RpcFuncExecutionError)
|
||||
resp.Message = err.Error()
|
||||
}
|
||||
}
|
@ -89,6 +89,9 @@ func (this *SCompGateRoute) Start() (err error) {
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayNoticeUserLogin), this.NoticeUserLogin) //注册用户登录通知
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayNoticeUserClose), this.NoticeUserClose) //注册用户离线通知
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_ConfigureUpDate), this.ConfigureUpDate) //注册配置更新
|
||||
if db.IsCross() { //跨服环境
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_DBSyncCross), this.DBSyncCross) //注册配置更新
|
||||
}
|
||||
err = this.ServiceCompBase.Start()
|
||||
return
|
||||
}
|
||||
@ -207,6 +210,13 @@ func (this *SCompGateRoute) ConfigureUpDate(ctx context.Context, args *pb.EmptyR
|
||||
return nil
|
||||
}
|
||||
|
||||
//RPC_DBSyncCross 接收配置更新消息
|
||||
func (this *SCompGateRoute) DBSyncCross(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) (err error) {
|
||||
log.Debugln("RPC_DBSyncCross")
|
||||
err = db.SyncServiceList()
|
||||
return
|
||||
}
|
||||
|
||||
//获取用户的会话对象
|
||||
func (this *SCompGateRoute) GetUserSession(udata *pb.CacheUser) (session comm.IUserSession) {
|
||||
session = this.pools.Get().(comm.IUserSession)
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
|
||||
type (
|
||||
ISys interface {
|
||||
//同步区服列表
|
||||
SyncServiceList() (err error)
|
||||
//本服数据连接
|
||||
Local() (conn *DBConn, err error)
|
||||
//当前是否是跨服
|
||||
@ -49,6 +51,11 @@ func NewSys(option ...Option) (sys ISys, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//同步区服列表
|
||||
func SyncServiceList() (err error) {
|
||||
return defsys.SyncServiceList()
|
||||
}
|
||||
|
||||
func Local() (conn *DBConn, err error) {
|
||||
return defsys.Local()
|
||||
}
|
||||
|
48
sys/db/db.go
48
sys/db/db.go
@ -93,6 +93,54 @@ func (this *DB) readercrossconf(path string) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//同步服务列表
|
||||
func (this *DB) SyncServiceList() (err error) {
|
||||
config := make(comm.CrossConfigs, 0)
|
||||
var (
|
||||
jsonFile *os.File
|
||||
byteValue []byte
|
||||
)
|
||||
if jsonFile, err = os.Open(this.options.CrossConfig); err != nil {
|
||||
return
|
||||
} else {
|
||||
defer jsonFile.Close()
|
||||
if byteValue, err = ioutil.ReadAll(jsonFile); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(byteValue, &config); err != nil {
|
||||
return
|
||||
}
|
||||
if cf, ok := config[this.options.CrossTag]; !ok {
|
||||
err = fmt.Errorf("no found Crossconfig:%s", this.options.CrossTag)
|
||||
return
|
||||
} else {
|
||||
if this.options.IsCross {
|
||||
for k, v := range cf.ServiceList {
|
||||
if _, ok := this.servers[k]; !ok {
|
||||
if this.servers[k], err = newDBConn(this.options.Log, DBConfig{
|
||||
RedisIsCluster: v.RedisIsCluster,
|
||||
RedisAddr: v.RedisAddr,
|
||||
RedisPassword: v.RedisPassword,
|
||||
RedisDB: v.RedisDB,
|
||||
MongodbUrl: v.MongodbUrl,
|
||||
MongodbDatabase: v.MongodbDatabase,
|
||||
}); err != nil {
|
||||
log.Error("comment db err!", log.Fields{"stag": k, "db": v, "err": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
err = errors.New("curr service is not cross!")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *DB) Local() (conn *DBConn, err error) {
|
||||
conn = this.local
|
||||
if conn == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user