From 24e2d92df7cad99e1e514fa581fe59765dbc4a12 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 02 八月 2019 09:54:33 +0800 Subject: [PATCH] rm discovery server --- controllers/dbtablesCon.go | 36 +++--- discovery/server.go | 110 +++++++++++----------- controllers/dbtableperson.go | 109 ++++++++++----------- 3 files changed, 125 insertions(+), 130 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 3a987c0..bad1888 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -1,12 +1,10 @@ package controllers import ( - "basic.com/pubsub/protomsg.git" "encoding/json" "log" "strconv" "time" - "webserver/discovery" "webserver/extend/logger" "github.com/gin-gonic/gin" @@ -16,7 +14,6 @@ "webserver/extend/esutil" "webserver/extend/util" "webserver/models" - esApi "basic.com/pubsub/esutil.git" ) type DbPersonController struct { @@ -63,16 +60,16 @@ params := string(personbytes) logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data, _ := esutil.PutEsDataReq(url, params) - if data["_id"] !=""{ - //閫氱煡姣斿杩涚▼缂撳瓨鏇存柊 - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTablePerson, - PersonId: personId, - TableId: []string{ dbperson.TableId }, - Feature: dbperson.FaceFeature, - Action: protomsg.DbAction_Insert, - }) - } + //if data["_id"] !=""{ + // //閫氱煡姣斿杩涚▼缂撳瓨鏇存柊 + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: personId, + // TableId: []string{ dbperson.TableId }, + // Feature: dbperson.FaceFeature, + // Action: protomsg.DbAction_Insert, + // }) + //} //c.JSON(200, changeEsRespData(data, "娣诲姞浜哄憳鎴愬姛")) result = changeEsRespData(data, "娣诲姞鎴愬姛") @@ -111,23 +108,23 @@ result := changeEsRespData(data, "淇敼鎴愬姛") if result["success"].(bool) { //code.Success.Message = "淇敼搴曞簱浜哄憳鎴愬姛" - if dbperson.Enable == 1 { - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTablePerson, - PersonId: dbperson.Id, - TableId: []string{ dbperson.TableId }, - Feature: "", - Action: protomsg.DbAction_Insert, - }) - } else { - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTablePerson, - PersonId: dbperson.Id, - TableId: []string{ dbperson.TableId }, - Feature: "", - Action: protomsg.DbAction_Delete, - }) - } + //if dbperson.Enable == 1 { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: dbperson.Id, + // TableId: []string{ dbperson.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Insert, + // }) + //} else { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: dbperson.Id, + // TableId: []string{ dbperson.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + //} util.ResponseFormat(c, code.Success, result["data"]) } else { //code.ServiceInsideError.Message += result["msg"].(string) @@ -159,18 +156,18 @@ if result["success"].(bool) { //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛" //閫氱煡姣斿杩涚▼锛屾浜哄凡鍒犻櫎 - dbperArr, e := esApi.Dbpersoninfosbyid([]string{uuid}, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) - if e ==nil && len(dbperArr) > 0{ - if dbperArr[0].TableId !=""{ - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTablePerson, - PersonId: uuid, - TableId: []string{ dbperArr[0].TableId }, - Feature: "", - Action: protomsg.DbAction_Delete, - }) - } - } + //dbperArr, e := esApi.Dbpersoninfosbyid([]string{uuid}, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) + //if e ==nil && len(dbperArr) > 0{ + // if dbperArr[0].TableId !=""{ + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: uuid, + // TableId: []string{ dbperArr[0].TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + // } + //} util.ResponseFormat(c, code.Success, result["data"]) } else { @@ -203,20 +200,20 @@ //result := changeEsRespData(data, "鍒犻櫎鎴愬姛") if data["error"] == nil { //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛" - dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) - if e ==nil && len(dbperArr) > 0{ - for _,esPer :=range dbperArr { - if esPer.TableId !=""{ - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTablePerson, - PersonId: esPer.Id, - TableId: []string{ esPer.TableId }, - Feature: "", - Action: protomsg.DbAction_Delete, - }) - } - } - } + //dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) + //if e ==nil && len(dbperArr) > 0{ + // for _,esPer :=range dbperArr { + // if esPer.TableId !=""{ + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: esPer.Id, + // TableId: []string{ esPer.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + // } + // } + //} util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛") } else { //code.ServiceInsideError.Message += result["msg"].(string) diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go index d3f9f89..cb21510 100644 --- a/controllers/dbtablesCon.go +++ b/controllers/dbtablesCon.go @@ -2,14 +2,12 @@ import ( "basic.com/dbapi.git" - "basic.com/pubsub/protomsg.git" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/satori/go.uuid" "log" "time" - "webserver/discovery" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" @@ -102,23 +100,23 @@ result := changeEsRespData(data, "淇敼鎴愬姛") if result["success"].(bool) { //code.Success.Message = "淇敼搴曞簱鎴愬姛" - if dbtable.Enable ==1 { - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTable, - PersonId: "", - TableId: []string{ dbtable.Id }, - Feature: "", - Action: protomsg.DbAction_Insert, - }) - } else { - discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ - Type: protomsg.EsCacheChanged_T_DbTable, - PersonId: "", - TableId: []string{ dbtable.Id }, - Feature: "", - Action: protomsg.DbAction_Delete, - }) - } + //if dbtable.Enable ==1 { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTable, + // PersonId: "", + // TableId: []string{ dbtable.Id }, + // Feature: "", + // Action: protomsg.DbAction_Insert, + // }) + //} else { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTable, + // PersonId: "", + // TableId: []string{ dbtable.Id }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + //} util.ResponseFormat(c, code.Success, result["data"]) } else { //code.ServiceInsideError.Message += result["msg"].(string) diff --git a/discovery/server.go b/discovery/server.go index 52ac5d3..4b37c53 100644 --- a/discovery/server.go +++ b/discovery/server.go @@ -1,57 +1,57 @@ package discovery -import ( - "basic.com/pubsub/protomsg.git" - "basic.com/valib/gopherdiscovery.git" - "github.com/gogo/protobuf/proto" - "time" - "webserver/extend/logger" -) - -const ( - Discovery_Server = "tcp://0.0.0.0:40008" - Discovery_UrlPubSub = "tcp://0.0.0.0:50008" -) - -//鍚姩discovery鐨剆erver -var discoveryServer *gopherdiscovery.DiscoveryServer -var dbChangeChan chan *protomsg.EsPersonCacheChange -func StartServer() { - var clients []string - var err error - var ( - defaultOpts = gopherdiscovery.Options{ - SurveyTime: 3 * time.Second, - //RecvDeadline: 3 * time.Second, - PollTime: 5 * time.Second, - } - ) - - discoveryServer, err = gopherdiscovery.Server(Discovery_Server, Discovery_UrlPubSub, defaultOpts) - - logger.Debug("server: ", discoveryServer) - logger.Debug("err:",err) - logger.Debug("clients: ",clients) - - dbChangeChan = make(chan *protomsg.EsPersonCacheChange) - - for { - select { - case dbMsg := <-dbChangeChan: - publishMessage(dbMsg) - } - } -} - -//骞挎挱鏁版嵁搴撴敼鍙樼殑msg -func publishMessage(msg *protomsg.EsPersonCacheChange) { - sendBytes,err := proto.Marshal(msg) - if err ==nil{ - discoveryServer.PublishMsg(string(sendBytes)) - } -} - -func AddDbMessage(msg *protomsg.EsPersonCacheChange) { - logger.Debug("MSG EsPersonCacheChange In") - dbChangeChan<-msg -} \ No newline at end of file +//import ( +// "basic.com/pubsub/protomsg.git" +// "basic.com/valib/gopherdiscovery.git" +// "github.com/gogo/protobuf/proto" +// "time" +// "webserver/extend/logger" +//) +// +//const ( +// Discovery_Server = "tcp://0.0.0.0:40008" +// Discovery_UrlPubSub = "tcp://0.0.0.0:50008" +//) +// +////鍚姩discovery鐨剆erver +//var discoveryServer *gopherdiscovery.DiscoveryServer +//var dbChangeChan chan *protomsg.EsPersonCacheChange +//func StartServer() { +// var clients []string +// var err error +// var ( +// defaultOpts = gopherdiscovery.Options{ +// SurveyTime: 3 * time.Second, +// //RecvDeadline: 3 * time.Second, +// PollTime: 5 * time.Second, +// } +// ) +// +// discoveryServer, err = gopherdiscovery.Server(Discovery_Server, Discovery_UrlPubSub, defaultOpts) +// +// logger.Debug("server: ", discoveryServer) +// logger.Debug("err:",err) +// logger.Debug("clients: ",clients) +// +// dbChangeChan = make(chan *protomsg.EsPersonCacheChange) +// +// for { +// select { +// case dbMsg := <-dbChangeChan: +// publishMessage(dbMsg) +// } +// } +//} +// +////骞挎挱鏁版嵁搴撴敼鍙樼殑msg +//func publishMessage(msg *protomsg.EsPersonCacheChange) { +// sendBytes,err := proto.Marshal(msg) +// if err ==nil{ +// discoveryServer.PublishMsg(string(sendBytes)) +// } +//} +// +//func AddDbMessage(msg *protomsg.EsPersonCacheChange) { +// logger.Debug("MSG EsPersonCacheChange In") +// dbChangeChan<-msg +//} \ No newline at end of file -- Gitblit v1.8.0