优化RPC连接

This commit is contained in:
GoEdgeLab
2021-11-10 22:22:27 +08:00
parent 55cefdb62c
commit 6116fa4f3e
7 changed files with 58 additions and 10 deletions

View File

@@ -48,6 +48,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
wg := &sync.WaitGroup{}
wg.Add(len(nodes))
for _, node := range nodes {
// TODO 检查是否在线
@@ -104,7 +105,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
},
NodeId: apiNode.UniqueId,
Secret: apiNode.Secret,
})
}, false)
if err != nil {
locker.Lock()
results = append(results, &MessageResult{
@@ -162,6 +163,11 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
})
}
// 关闭RPC
for _, rpcClient := range rpcMap {
_ = rpcClient.Close()
}
return
}
@@ -279,7 +285,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
},
NodeId: apiNode.UniqueId,
Secret: apiNode.Secret,
})
}, false)
if err != nil {
locker.Lock()
results = append(results, &MessageResult{
@@ -337,5 +343,10 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
})
}
// 关闭RPC
for _, rpcClient := range rpcMap {
_ = rpcClient.Close()
}
return
}