mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化网关服务
This commit is contained in:
@@ -108,7 +108,7 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo (nodeInfo *NodeInfo){
|
|||||||
rpcInfo := NodeRpcInfo{}
|
rpcInfo := NodeRpcInfo{}
|
||||||
rpcInfo.nodeInfo = *nodeInfo
|
rpcInfo.nodeInfo = *nodeInfo
|
||||||
rpcInfo.client = &rpc.Client{}
|
rpcInfo.client = &rpc.Client{}
|
||||||
rpcInfo.client.Connect(nodeInfo.ListenAddr)
|
rpcInfo.client.Connect(nodeInfo.NodeId,nodeInfo.ListenAddr)
|
||||||
cls.mapRpc[nodeInfo.NodeId] = rpcInfo
|
cls.mapRpc[nodeInfo.NodeId] = rpcInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ func (cls *Cluster) buildLocalRpc(){
|
|||||||
rpcInfo := NodeRpcInfo{}
|
rpcInfo := NodeRpcInfo{}
|
||||||
rpcInfo.nodeInfo = cls.localNodeInfo
|
rpcInfo.nodeInfo = cls.localNodeInfo
|
||||||
rpcInfo.client = &rpc.Client{}
|
rpcInfo.client = &rpc.Client{}
|
||||||
rpcInfo.client.Connect("")
|
rpcInfo.client.Connect(rpcInfo.nodeInfo.NodeId,"")
|
||||||
|
|
||||||
cls.mapRpc[cls.localNodeInfo.NodeId] = rpcInfo
|
cls.mapRpc[cls.localNodeInfo.NodeId] = rpcInfo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
id int
|
||||||
bSelfNode bool
|
bSelfNode bool
|
||||||
network.TCPClient
|
network.TCPClient
|
||||||
conn *network.TCPConn
|
conn *network.TCPConn
|
||||||
@@ -34,7 +35,8 @@ func (client *Client) NewClientAgent(conn *network.TCPConn) network.Agent {
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Connect(addr string) error {
|
func (client *Client) Connect(id int,addr string) error {
|
||||||
|
client.id = id
|
||||||
client.Addr = addr
|
client.Addr = addr
|
||||||
client.maxCheckCallRpcCount = 1000
|
client.maxCheckCallRpcCount = 1000
|
||||||
client.callRpcTimeout = 15*time.Second
|
client.callRpcTimeout = 15*time.Second
|
||||||
@@ -316,4 +318,8 @@ func (client *Client) OnClose(){
|
|||||||
|
|
||||||
func (client *Client) IsConnected() bool {
|
func (client *Client) IsConnected() bool {
|
||||||
return client.conn!=nil && client.conn.IsConnected()==true
|
return client.conn!=nil && client.conn.IsConnected()==true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) GetId() int{
|
||||||
|
return client.id
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package tcpgateway
|
package tcpgateway
|
||||||
|
|
||||||
type ILoadBalance interface {
|
type ILoadBalance interface {
|
||||||
SelectNode(serviceName string) int //选择一个结点,通过服务名称
|
SelectNode(serviceName string,clientId uint64,eventType string,msgType uint16,msg []byte) int //选择一个结点,通过服务名称
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ package tcpgateway
|
|||||||
type LoadBalance struct {
|
type LoadBalance struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (balance *LoadBalance) SelectNode(serviceName string) int {
|
func (balance *LoadBalance) SelectNode(serviceName string,clientId uint64,eventType string,msgType uint16,msg []byte) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ func (args RawInputArgs) DoGc() {
|
|||||||
}
|
}
|
||||||
network.ReleaseByteSlice(args.rawData)
|
network.ReleaseByteSlice(args.rawData)
|
||||||
}
|
}
|
||||||
|
var msgEventType string
|
||||||
|
|
||||||
func (r *Router) RouterMessage(cliId uint64,msgType uint16,msg []byte) {
|
func (r *Router) RouterMessage(cliId uint64,msgType uint16,msg []byte) {
|
||||||
routerInfo:= r.GetMsgRouterService(msgType)
|
routerInfo:= r.GetMsgRouterService(msgType)
|
||||||
@@ -221,7 +222,7 @@ func (r *Router) RouterMessage(cliId uint64,msgType uint16,msg []byte) {
|
|||||||
|
|
||||||
routerId := r.GetRouterId(cliId,&routerInfo.ServiceName)
|
routerId := r.GetRouterId(cliId,&routerInfo.ServiceName)
|
||||||
if routerId ==0 {
|
if routerId ==0 {
|
||||||
routerId = r.loadBalance.SelectNode(routerInfo.ServiceName)
|
routerId = r.loadBalance.SelectNode(routerInfo.ServiceName,cliId,msgEventType,msgType,msg)
|
||||||
r.SetRouterId(cliId,routerInfo.ServiceName,routerId)
|
r.SetRouterId(cliId,routerInfo.ServiceName,routerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ func (r *Router) RouterEvent(clientId uint64,eventType string) bool{
|
|||||||
|
|
||||||
routerId := r.GetRouterId(clientId,&routerInfo.ServiceName)
|
routerId := r.GetRouterId(clientId,&routerInfo.ServiceName)
|
||||||
if routerId ==0 {
|
if routerId ==0 {
|
||||||
routerId = r.loadBalance.SelectNode(routerInfo.ServiceName)
|
routerId = r.loadBalance.SelectNode(routerInfo.ServiceName,clientId,eventType,0,nil)
|
||||||
r.SetRouterId(clientId,routerInfo.ServiceName,routerId)
|
r.SetRouterId(clientId,routerInfo.ServiceName,routerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ import (
|
|||||||
"github.com/duanhf2012/origin/sysservice/tcpservice"
|
"github.com/duanhf2012/origin/sysservice/tcpservice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init(){
|
|
||||||
node.Setup(&tcpservice.TcpService{})
|
|
||||||
node.Setup(&TcpGateService{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type MsgTypeRouterInfo struct {
|
type MsgTypeRouterInfo struct {
|
||||||
router IRouter
|
router IRouter
|
||||||
serviceName string
|
serviceName string
|
||||||
|
|||||||
Reference in New Issue
Block a user