goProject/trunk/center/common/rabbitmq/send_data.go
2025-01-23 16:12:49 +08:00

35 lines
842 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rabbitmq
import (
configYaml "common/configsYaml"
"goutil/logUtilPlus"
"strconv"
"github.com/streadway/amqp"
)
// SendMqData 发送单挑mq消息
func SendMqData(dbIndex int32, data string) {
rabbitMQName := configYaml.GetRabbitMQName() + ":" + strconv.Itoa(int(dbIndex))
// 确保通道启用了 Publisher Confirms
if err := RabbitMQChannel.Confirm(false); err != nil {
logUtilPlus.ErrorLog("channel could not be put into confirm mode: %w", err)
}
// 发布消息到队列
err := RabbitMQChannel.Publish(
"", // 交换机名称
rabbitMQName, // 路由键
false, // 是否强制
false, // 是否立即
amqp.Publishing{
ContentType: "text/plain",
Body: []byte(data),
})
if err != nil {
logUtilPlus.ErrorLog("Failed to publish a messageerr:%s", err.Error())
}
}