mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
1.支持动态服务发现功能
2.Service中支持对RPC结点连接或断开事件监听
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
1181
rpc/dynamicdiscover.pb.go
Normal file
1181
rpc/dynamicdiscover.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
29
rpc/dynamicdiscover.proto
Normal file
29
rpc/dynamicdiscover.proto
Normal file
@@ -0,0 +1,29 @@
|
||||
syntax = "proto3";
|
||||
package rpc;
|
||||
option go_package = "./rpc";
|
||||
|
||||
message NodeInfo{
|
||||
int32 NodeId = 1;
|
||||
string NodeName = 2;
|
||||
string ListenAddr = 3;
|
||||
bool Private = 4;
|
||||
repeated string PublicServiceList = 5;
|
||||
}
|
||||
|
||||
//Client->Master
|
||||
message ServiceDiscoverReq{
|
||||
NodeInfo nodeInfo = 1;
|
||||
}
|
||||
|
||||
//Master->Client
|
||||
message SubscribeDiscoverNotify{
|
||||
bool IsFull = 1;
|
||||
int32 DelNodeId = 2;
|
||||
repeated NodeInfo nodeInfo = 3;
|
||||
}
|
||||
|
||||
|
||||
//Master->Client
|
||||
message ServiceDiscoverRes{
|
||||
repeated NodeInfo nodeInfo = 1;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: bin/gogopb/gogorpc.proto
|
||||
// source: rpc/gogorpc.proto
|
||||
|
||||
package rpc
|
||||
|
||||
@@ -37,7 +37,7 @@ func (m *GoGoPBRpcRequestData) Reset() { *m = GoGoPBRpcRequestData{} }
|
||||
func (m *GoGoPBRpcRequestData) String() string { return proto.CompactTextString(m) }
|
||||
func (*GoGoPBRpcRequestData) ProtoMessage() {}
|
||||
func (*GoGoPBRpcRequestData) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_b3b900b0f45d7fb5, []int{0}
|
||||
return fileDescriptor_38afb24c36168563, []int{0}
|
||||
}
|
||||
func (m *GoGoPBRpcRequestData) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -114,7 +114,7 @@ func (m *GoGoPBRpcResponseData) Reset() { *m = GoGoPBRpcResponseData{} }
|
||||
func (m *GoGoPBRpcResponseData) String() string { return proto.CompactTextString(m) }
|
||||
func (*GoGoPBRpcResponseData) ProtoMessage() {}
|
||||
func (*GoGoPBRpcResponseData) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_b3b900b0f45d7fb5, []int{1}
|
||||
return fileDescriptor_38afb24c36168563, []int{1}
|
||||
}
|
||||
func (m *GoGoPBRpcResponseData) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@@ -169,26 +169,25 @@ func init() {
|
||||
proto.RegisterType((*GoGoPBRpcResponseData)(nil), "rpc.GoGoPBRpcResponseData")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("bin/gogopb/gogorpc.proto", fileDescriptor_b3b900b0f45d7fb5) }
|
||||
func init() { proto.RegisterFile("rpc/gogorpc.proto", fileDescriptor_38afb24c36168563) }
|
||||
|
||||
var fileDescriptor_b3b900b0f45d7fb5 = []byte{
|
||||
// 241 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0xca, 0xcc, 0xd3,
|
||||
0x4f, 0xcf, 0x4f, 0xcf, 0x2f, 0x48, 0x02, 0x53, 0x45, 0x05, 0xc9, 0x7a, 0x05, 0x45, 0xf9, 0x25,
|
||||
0xf9, 0x42, 0xcc, 0x45, 0x05, 0xc9, 0x4a, 0x4b, 0x18, 0xb9, 0x44, 0xdc, 0xf3, 0xdd, 0xf3, 0x03,
|
||||
0x9c, 0x82, 0x0a, 0x92, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x5c, 0x12, 0x4b, 0x12, 0x85,
|
||||
0x04, 0xb8, 0x98, 0x83, 0x53, 0x0b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, 0x40, 0x4c, 0x21,
|
||||
0x05, 0x2e, 0xee, 0xa0, 0x82, 0x64, 0xdf, 0xd4, 0x92, 0x8c, 0xfc, 0x14, 0xcf, 0x14, 0x09, 0x26,
|
||||
0x05, 0x46, 0x0d, 0xde, 0x20, 0x64, 0x21, 0x21, 0x15, 0x2e, 0xde, 0xe0, 0xd4, 0xa2, 0xb2, 0xcc,
|
||||
0xe4, 0x54, 0x88, 0x90, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0xaa, 0xa0, 0x90, 0x04, 0x17,
|
||||
0xbb, 0x5f, 0x7e, 0x50, 0x6a, 0x41, 0x4e, 0xa5, 0x04, 0x8b, 0x02, 0xa3, 0x06, 0x47, 0x10, 0x8c,
|
||||
0x0b, 0x92, 0xf1, 0xcc, 0x0b, 0x48, 0x2c, 0x4a, 0xcc, 0x95, 0x60, 0x55, 0x60, 0xd4, 0xe0, 0x09,
|
||||
0x82, 0x71, 0x95, 0x42, 0xb9, 0x44, 0x91, 0x5c, 0x59, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x8a, 0xc3,
|
||||
0x99, 0x22, 0x5c, 0xac, 0xae, 0x45, 0x45, 0xf9, 0x45, 0x60, 0x07, 0x72, 0x06, 0x41, 0x38, 0x20,
|
||||
0x51, 0x88, 0x95, 0xcc, 0x60, 0x83, 0x21, 0x1c, 0x27, 0xe1, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c,
|
||||
0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x31, 0x8a, 0x55, 0x4f, 0xbf, 0xa8, 0x20, 0x39, 0x89, 0x0d,
|
||||
0x1c, 0x3c, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x18, 0x52, 0x1a, 0x3a, 0x01, 0x00,
|
||||
0x00,
|
||||
var fileDescriptor_38afb24c36168563 = []byte{
|
||||
// 237 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2c, 0x2a, 0x48, 0xd6,
|
||||
0x4f, 0xcf, 0x4f, 0xcf, 0x2f, 0x2a, 0x48, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2e,
|
||||
0x2a, 0x48, 0x56, 0x5a, 0xc2, 0xc8, 0x25, 0xe2, 0x9e, 0xef, 0x9e, 0x1f, 0xe0, 0x14, 0x54, 0x90,
|
||||
0x1c, 0x94, 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0xe2, 0x92, 0x58, 0x92, 0x28, 0x24, 0xc0, 0xc5, 0x1c,
|
||||
0x9c, 0x5a, 0x28, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x12, 0x04, 0x62, 0x0a, 0x29, 0x70, 0x71, 0x07,
|
||||
0x15, 0x24, 0xfb, 0xa6, 0x96, 0x64, 0xe4, 0xa7, 0x78, 0xa6, 0x48, 0x30, 0x29, 0x30, 0x6a, 0xf0,
|
||||
0x06, 0x21, 0x0b, 0x09, 0xa9, 0x70, 0xf1, 0x06, 0xa7, 0x16, 0x95, 0x65, 0x26, 0xa7, 0x42, 0x84,
|
||||
0x24, 0x98, 0x15, 0x18, 0x35, 0x38, 0x83, 0x50, 0x05, 0x85, 0x24, 0xb8, 0xd8, 0xfd, 0xf2, 0x83,
|
||||
0x52, 0x0b, 0x72, 0x2a, 0x25, 0x58, 0x14, 0x18, 0x35, 0x38, 0x82, 0x60, 0x5c, 0x90, 0x8c, 0x67,
|
||||
0x5e, 0x40, 0x62, 0x51, 0x62, 0xae, 0x04, 0xab, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x8c, 0xab, 0x14,
|
||||
0xca, 0x25, 0x8a, 0xe4, 0xca, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x1c, 0xce, 0x14, 0xe1, 0x62,
|
||||
0x75, 0x2d, 0x2a, 0xca, 0x2f, 0x02, 0x3b, 0x90, 0x33, 0x08, 0xc2, 0x01, 0x89, 0x42, 0xac, 0x64,
|
||||
0x06, 0x1b, 0x0c, 0xe1, 0x38, 0x09, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83,
|
||||
0x47, 0x72, 0x8c, 0x51, 0xac, 0x7a, 0xfa, 0x45, 0x05, 0xc9, 0x49, 0x6c, 0xe0, 0xe0, 0x31, 0x06,
|
||||
0x04, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xfc, 0x50, 0x87, 0x33, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GoGoPBRpcRequestData) Marshal() (dAtA []byte, err error) {
|
||||
|
||||
@@ -63,7 +63,7 @@ type RpcHandler struct {
|
||||
callResponseCallBack chan *Call //异步返回的回调
|
||||
}
|
||||
|
||||
type TriggerRpcEvent func(bConnect bool,nodeId int)
|
||||
type TriggerRpcEvent func(bConnect bool,clientSeq uint32,nodeId int)
|
||||
type IRpcListener interface {
|
||||
OnRpcConnected(nodeId int)
|
||||
OnRpcDisconnect(nodeId int)
|
||||
@@ -467,6 +467,9 @@ func (handler *RpcHandler) asyncCallRpc(nodeid int,serviceMethod string,args int
|
||||
var pClientList [maxClusterNode]*Client
|
||||
err,count := handler.funcRpcClient(nodeid,serviceMethod,pClientList[:])
|
||||
if count==0||err != nil {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("cannot find rpcclient from nodeid %d serviceMethod %s",nodeid,serviceMethod)
|
||||
}
|
||||
fVal.Call([]reflect.Value{reflect.ValueOf(reply),reflect.ValueOf(err)})
|
||||
log.Error("Call serviceMethod is error:%+v!",err)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user