1.支持动态服务发现功能

2.Service中支持对RPC结点连接或断开事件监听
This commit is contained in:
boyce
2021-04-29 17:18:13 +08:00
parent 63c2ac4c98
commit a60ad1cccf
16 changed files with 1797 additions and 158 deletions

View File

@@ -15,6 +15,7 @@ import (
)
type Client struct {
clientSeq uint32
id int
bSelfNode bool
network.TCPClient
@@ -29,6 +30,8 @@ type Client struct {
TriggerRpcEvent
}
var clientSeq uint32
func (client *Client) NewClientAgent(conn *network.TCPConn) network.Agent {
client.conn = conn
client.ResetPending()
@@ -37,6 +40,7 @@ func (client *Client) NewClientAgent(conn *network.TCPConn) network.Agent {
}
func (client *Client) Connect(id int,addr string) error {
client.clientSeq = atomic.AddUint32(&clientSeq,1)
client.id = id
client.Addr = addr
client.maxCheckCallRpcCount = 1000
@@ -82,9 +86,6 @@ func (client *Client) makeCallFail(call *Call){
}else{
call.done <- call
}
}
func (client *Client) checkRpcCallTimeout(){
@@ -263,7 +264,7 @@ func (client *Client) Run(){
}
}()
client.TriggerRpcEvent(true,client.GetId())
client.TriggerRpcEvent(true,client.GetClientSeq(),client.GetId())
for {
bytes,err := client.conn.ReadMsg()
if err != nil {
@@ -319,7 +320,7 @@ func (client *Client) Run(){
}
func (client *Client) OnClose(){
client.TriggerRpcEvent(false,client.GetId())
client.TriggerRpcEvent(false,client.GetClientSeq(),client.GetId())
}
func (client *Client) IsConnected() bool {
@@ -329,3 +330,11 @@ func (client *Client) IsConnected() bool {
func (client *Client) GetId() int{
return client.id
}
func (client *Client) Close(waitDone bool){
client.TCPClient.Close(waitDone)
}
func (client *Client) GetClientSeq() uint32 {
return client.clientSeq
}