[agent-go] 调整代码结构
This commit is contained in:
72
agent-go/rabbitmq/OMsgConnector.go
Normal file
72
agent-go/rabbitmq/OMsgConnector.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package rabbitmq
|
||||
|
||||
import (
|
||||
"agent-go/g"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var OctopusToServerQueue = &RabbitQueue{}
|
||||
|
||||
func BuildOMsgRuntimeConnectorQueue(agentTopicName string) {
|
||||
|
||||
// 建立 业务消息 接收队列
|
||||
// agentTopicName为名称的队列
|
||||
nacosConfig := g.G.NacosConfig
|
||||
|
||||
octopusExchangeName := nacosConfig.GetString("octopus.message.octopus_exchange")
|
||||
|
||||
octopusConnectProp := &ConnectProperty{
|
||||
ExchangeName: octopusExchangeName,
|
||||
QueueName: agentTopicName,
|
||||
ExchangeType: g.QueueTopic,
|
||||
TopicKey: agentTopicName + "*",
|
||||
}
|
||||
|
||||
octopusMsgQueue := &RabbitQueue{
|
||||
RabbitProp: octopusConnectProp,
|
||||
}
|
||||
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
|
||||
|
||||
octopusToServerQueueName := nacosConfig.GetString("octopus.message.octopus_to_server")
|
||||
|
||||
octopusToServerProp := &ConnectProperty{
|
||||
ExchangeName: octopusExchangeName,
|
||||
QueueName: octopusToServerQueueName,
|
||||
ExchangeType: g.QueueTopic,
|
||||
TopicKey: octopusToServerQueueName,
|
||||
}
|
||||
|
||||
OctopusToServerQueue = &RabbitQueue{
|
||||
RabbitProp: octopusToServerProp,
|
||||
}
|
||||
|
||||
// 开启运行时消息返回队列
|
||||
OctopusToServerQueue.Connect()
|
||||
|
||||
log.InfoF("Octopus Message Replay Queue is established ! => %v", OctopusToServerQueue)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user