[ Server ] accomplish alive status precedure
This commit is contained in:
@@ -22,20 +22,20 @@ func INIT() *AgentServerInfo {
|
||||
// 获取系统的环境变量
|
||||
agentServerInfo := parseAgentServerInfo()
|
||||
|
||||
nacosConfig := g.G.AgentConfig
|
||||
agentConfig := g.G.AgentConfig
|
||||
|
||||
initToServerProp := &rabbitmq.ConnectProperty{
|
||||
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: nacosConfig.GetString("octopus.message.init_to_server"),
|
||||
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: agentConfig.GetString("octopus.message.init_to_server"),
|
||||
ExchangeType: g.QueueDirect,
|
||||
TopicKey: nacosConfig.GetString("octopus.message.init_to_server_key"),
|
||||
TopicKey: agentConfig.GetString("octopus.message.init_to_server_key"),
|
||||
}
|
||||
|
||||
initFromServerProp := &rabbitmq.ConnectProperty{
|
||||
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: nacosConfig.GetString("octopus.message.init_from_server"),
|
||||
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: agentConfig.GetString("octopus.message.init_from_server"),
|
||||
ExchangeType: g.QueueDirect,
|
||||
TopicKey: nacosConfig.GetString("octopus.message.init_from_server_key"),
|
||||
TopicKey: agentConfig.GetString("octopus.message.init_from_server_key"),
|
||||
}
|
||||
|
||||
// 建立RabbitMQ的连接
|
||||
@@ -96,6 +96,9 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
|
||||
|
||||
initOctopusMessageDeliveries := initFromServerQueue.Read(false)
|
||||
|
||||
// 2023年6月19日 修复注册信息一直没有完全消费的问题
|
||||
findRealAgentTopicName := ""
|
||||
|
||||
// 同步很多抢占注册的情况
|
||||
for delivery := range initOctopusMessageDeliveries {
|
||||
|
||||
@@ -128,29 +131,34 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
|
||||
// 修改系统参数
|
||||
g.G.AgentHasRegister = true
|
||||
|
||||
// 建立 运行时 RabbitMQ连接
|
||||
agentTopicName := initOctopusMsg.Result.(string)
|
||||
rabbitmq.BuildOMsgRuntimeConnectorQueue(agentTopicName)
|
||||
// 保存真实的AgentTopicName
|
||||
findRealAgentTopicName = serverInfo.TopicName
|
||||
|
||||
// 手动关闭 注册队列的连接
|
||||
shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
|
||||
return
|
||||
|
||||
} else {
|
||||
// 不是自身的 注册回复信息 -- 拒绝 2023年6月19日 此处存在错误! 会死循环Nack 导致异常
|
||||
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body))
|
||||
delivery.Ack(false)
|
||||
|
||||
// 需要休眠等待不再获取相应的信息
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
||||
// 不是自身的 注册回复信息 -- 拒绝
|
||||
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body))
|
||||
delivery.Nack(false, true)
|
||||
|
||||
// 需要休眠等待不再获取相应的信息
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
}
|
||||
|
||||
// 建立 运行时 RabbitMQ连接
|
||||
rabbitmq.BuildOMsgRuntimeConnectorQueue(findRealAgentTopicName)
|
||||
|
||||
}
|
||||
|
||||
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
|
||||
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
|
||||
log.InfoF("Shutdown register queue connection !")
|
||||
|
||||
initFromServerQueue.Close()
|
||||
initToServerQueue.Close()
|
||||
|
||||
log.InfoF("Pretend to Shutdown register queue connection !")
|
||||
}
|
||||
|
||||
func parseAgentServerInfo() *AgentServerInfo {
|
||||
|
||||
Reference in New Issue
Block a user