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 message，err:%s", err.Error())
	}
}
