Skip to content

Commit

Permalink
修改客户端调用代码,减少每次都要去etcd读取配置信息
Browse files Browse the repository at this point in the history
  • Loading branch information
hwholiday committed Jan 23, 2019
1 parent 1d9c22c commit a5f55a9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions api_agent/server/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"log"
"github.com/gin-gonic/gin"
"os"
"github.com/micro/go-micro/selector/cache"
"github.com/micro/go-micro/selector"
)

var Client *Server
Expand Down Expand Up @@ -51,17 +53,19 @@ func InitServer(r *gin.Engine, args ...string) {
)

serviceDb := micro.NewService(
micro.Name(args[2]+".client"),
micro.Registry(registry),
micro.Name(args[2]),
micro.Version("v1"),
micro.Broker(nsqBroker),
micro.RegisterTTL(time.Second*30),
micro.RegisterInterval(time.Second*15),
//节点信息缓存30秒
micro.Selector(cache.NewSelector(
cache.TTL(time.Second*30),
selector.Registry(registry),
)),
)
serviceDb.Init()
Client.DbAgent = dbagent.NewDbAgentServerService(args[2], serviceDb.Client())


Client.Pub = micro.NewPublisher(args[3], cli)
Client.Pub.Publish(context.Background(), &logagent.Log{Time: time.Now().Unix(), Error: "apiapiapi ", Data: "api_agent启动成功", Filename: "apiapiapi", Line: "35", Method: "apiapiapi"})

Expand Down

0 comments on commit a5f55a9

Please sign in to comment.