package mq

import (
	"errors"
	"mtp20access/client"
	"mtp20access/model/mq/request"
	"mtp20access/rabbitmq"
)

// SendNtfMQ 向总线发送通知类信息
func SendNtfMQ(req *request.MQNtfReq, sessionID int) (err error) {
	// 将请求的数据转换成总线使用的Protobuf
	bytes, err := req.GetProtoBytes()
	if err != nil {
		return
	}
	if bytes == nil {
		err = errors.New("请求信息序列化失败")
		return
	}

	// 向总线发送业务信息
	packet := &client.MQPacket{
		FunCode:   req.FunCode,
		SessionId: uint32(sessionID),
		Data:      bytes,
	}
	go rabbitmq.Publish(req.Topic, packet)

	return
}
