[agent-go] 调通Executor的代码
This commit is contained in:
@@ -2,6 +2,7 @@ package rabbitmq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
@@ -24,16 +25,19 @@ func Send(conn *RabbitMQConn, connProp *ConnectProperty, message []byte) {
|
||||
channel := conn.Channel
|
||||
|
||||
// 发送
|
||||
channel.Publish(
|
||||
err := channel.Publish(
|
||||
connProp.ExchangeName,
|
||||
connProp.TopicKey,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
amqp.Publishing{
|
||||
ContentType: "text/plain",
|
||||
Body: message,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to publish a message: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func Read(conn *RabbitMQConn, connProp *ConnectProperty, autoAck bool) <-chan amqp.Delivery {
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
|
||||
func HandleOMsg(initOMsgFromServer *config.OctopusMessage) {
|
||||
|
||||
agentTopicName := initOMsgFromServer.UUID
|
||||
agentTopicName := initOMsgFromServer.Result.(string)
|
||||
|
||||
OctopusExchange := g.G.NacosConfig.GetString("octopus.message.octopus_exchange")
|
||||
|
||||
octopusConnectProp := &ConnectProperty{
|
||||
@@ -47,7 +48,7 @@ func HandleOMsg(initOMsgFromServer *config.OctopusMessage) {
|
||||
var om *config.OctopusMessage
|
||||
err := json.Unmarshal(delivery.Body, &om)
|
||||
if err != nil {
|
||||
log.Error("Octopus Message Parse Error !")
|
||||
log.Error(fmt.Sprintf("octopus message convert to json is wrong! msg is => %s", delivery.Body))
|
||||
// 保存到某处
|
||||
continue
|
||||
}
|
||||
@@ -80,12 +81,12 @@ func executorOMHandler(octopusMessage *config.OctopusMessage) {
|
||||
var executionMessage *config.ExecutionMessage
|
||||
err := json.Unmarshal([]byte(executionMsgString), &executionMessage)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("execution message convert to json is wrong! msg is => %s", executionMsgString))
|
||||
return
|
||||
}
|
||||
|
||||
// 交给后端的实际处理器处理, 再次策略
|
||||
executor.Execute(octopusMessage, executionMessage)
|
||||
|
||||
}
|
||||
|
||||
func statusOMHandler(octopusMessage *config.OctopusMessage) {
|
||||
|
||||
@@ -44,6 +44,12 @@ func NewRabbitMQConn(property *ConnectProperty) (*RabbitMQConn, error) {
|
||||
|
||||
// 获取RabbitMQ的连接
|
||||
conn := GetInstance()
|
||||
// 获取RabbitMQ的连接地址
|
||||
//rabbitMQEndpointFromG := parseRabbitMQEndpointFromG()
|
||||
//conn, err := amqp.Dial(rabbitMQEndpointFromG)
|
||||
//if err != nil {
|
||||
// log.Error(fmt.Sprintf("failed to connect to RabbitMQ: %v", err))
|
||||
//}
|
||||
|
||||
ch, err := conn.Channel()
|
||||
if err != nil {
|
||||
@@ -53,7 +59,7 @@ func NewRabbitMQConn(property *ConnectProperty) (*RabbitMQConn, error) {
|
||||
if err = ch.ExchangeDeclare(
|
||||
property.ExchangeName, // name of the exchange
|
||||
property.ExchangeType, // type of the exchange
|
||||
true, // durable
|
||||
false, // durable
|
||||
false, // delete when complete
|
||||
false, // internal
|
||||
false, // noWait
|
||||
@@ -64,7 +70,7 @@ func NewRabbitMQConn(property *ConnectProperty) (*RabbitMQConn, error) {
|
||||
|
||||
_, err = ch.QueueDeclare(
|
||||
property.QueueName, // name of the queue
|
||||
true, // durable
|
||||
false, // durable
|
||||
false, // delete when unused
|
||||
false, // exclusive
|
||||
false, // noWait
|
||||
|
||||
Reference in New Issue
Block a user