[agent-go] 优化代码,完成连通性测试

This commit is contained in:
zeaslity
2023-03-30 15:10:27 +08:00
parent 124143c6c6
commit d24a338e80
6 changed files with 65 additions and 73 deletions

View File

@@ -20,7 +20,7 @@ const (
InitOmType = "INIT"
)
var pool, _ = ants.NewPool(100, ants.WithNonblocking(true), ants.WithLogger(logger2.Log))
var pool, _ = ants.NewPool(100, ants.WithNonblocking(false), ants.WithLogger(logger2.Log), ants.WithMaxBlockingTasks(30), ants.WithDisablePurge(true))
var G = NewGlobal(
pool,

View File

@@ -10,8 +10,8 @@ spring:
config-retry-time: 3000
file-extension: yaml
max-retry: 3
server-addr: "150.230.198.103:21060"
# server-addr: "42.192.52.227:21060"
# server-addr: "150.230.198.103:21060"
server-addr: "42.192.52.227:21060"
timeout: 5000
config-long-poll-timeout: 5000
extension-configs:

View File

@@ -28,26 +28,6 @@ func BuildOMsgRuntimeConnectorQueue(agentTopicName string) {
}
octopusMsgQueue.Connect()
deliveries := octopusMsgQueue.Read(true)
// 死循环处理Octopus Message
P.Submit(
func() {
for delivery := range deliveries {
var om *OctopusMessage
err := json.Unmarshal(delivery.Body, &om)
if err != nil {
log.Error(fmt.Sprintf("octopus message convert to json is wrong! msg is => %s", delivery.Body))
// 保存到某处
continue
}
// 策略模式 处理消息
om.Handle()
}
})
// 建立 业务消息 返回队列
// 统一为 OctopusToServer
@@ -67,6 +47,29 @@ func BuildOMsgRuntimeConnectorQueue(agentTopicName string) {
// 开启运行时消息返回队列
OctopusToServerQueue.Connect()
log.InfoF("Octopus Message Replay Queue is established ! => %v", OctopusToServerQueue)
log.InfoF("Octopus Message Business Runtime Queue is established ! => %v", OctopusToServerQueue)
deliveries := octopusMsgQueue.Read(true)
forever := make(chan bool)
P.Submit(
func() {
// 死循环处理Octopus Message
for delivery := range deliveries {
var om *OctopusMessage
err := json.Unmarshal(delivery.Body, &om)
if err != nil {
log.Error(fmt.Sprintf("octopus message convert to json is wrong! msg is => %s", delivery.Body))
// 保存到某处
continue
}
// 策略模式 处理消息
om.Handle()
}
})
// wait forever
<-forever
}

View File

@@ -57,18 +57,18 @@ func INIT() *AgentServerInfo {
if err != nil {
log.Error(fmt.Sprintf("octopus message convert to json is wrong! msg is => %v", octopusMsg))
}
log.Debug(fmt.Sprintf("Prepare to send init message to server! ==> %s", string(msgBytes)))
// 发送OM至MQ中
P.Submit(
func() {
for g.G.AgentHasRegister == false {
log.Debug(fmt.Sprintf("Send init message to server! ==> %s", string(msgBytes)))
//如果agent存活 而Server不存活 那么需要持续不断的向Server中发送消息
initToServerQueue.Send(
msgBytes,
)
// 休眠
time.Sleep(10 * time.Minute)
@@ -96,12 +96,6 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
initOctopusMessageDeliveries := initFromServerQueue.Read(false)
forever := make(chan bool)
// use the ant goroutine pool
P.Submit(
func() {
// 同步很多抢占注册的情况
for delivery := range initOctopusMessageDeliveries {
@@ -126,17 +120,20 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
// 处理OM信息
if initOctopusMsg != nil && initOctopusMsg.Type == g.InitOmType && serverName == agentServerInfo.ServerName {
// 是本机的注册回复信息
log.InfoF("OctopusMessage INIT from server is this agent !")
// 手动确认信息
delivery.Ack(false)
// 修改系统参数
g.G.AgentHasRegister = true
// 建立 运行时 RabbitMQ连接
agentTopicName := initOctopusMsg.Result.(string)
rabbitmq.BuildOMsgRuntimeConnectorQueue(agentTopicName)
// 手动确认信息
delivery.Ack(false)
// 手动关闭 注册队列的连接
shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
return
}
@@ -145,17 +142,11 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
delivery.Nack(false, true)
}
},
)
// wait forever
<-forever
}
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
log.InfoF("Shutdown register queue connection !")
}
func parseAgentServerInfo() *AgentServerInfo {

Binary file not shown.

View File

@@ -78,8 +78,6 @@ services:
- MYSQL_SERVICE_PASSWORD=Superwmm.23
depends_on:
- mysql
volumes:
- 'rabbitmq_data:/bitnami/rabbitmq/mnesia'
# redis-replica:
# image: redis-image