|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package consume
-
- import (
- "applet/app/cfg"
- "applet/app/db"
- utils2 "applet/app/utils"
- "applet/app/utils/logx"
- "applet/consume/md"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy"
- md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/streadway/amqp"
- )
-
- func EggEnergyStartExchangeGreenEnergyConsume(queue md.MqQueue) {
- fmt.Println(">>>>>>>>>>>>EggEnergyStartExchangeGreenEnergyConsume>>>>>>>>>>>>")
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err != nil {
- logx.Error(err)
- return
- }
- defer ch.Release()
- //1、将自己绑定到交换机上
- ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
- //2、取出数据进行消费
- ch.Qos(1)
- delivery := ch.Consume(queue.Name, false)
-
- egg_system_rules.Init(cfg.RedisAddr)
- var res amqp.Delivery
- var ok bool
- for {
- res, ok = <-delivery
- if ok == true {
- err = handleEggEnergyStartExchangeGreenEnergyConsume(res.Body, ch)
- if err != nil {
- fmt.Println("EggEnergyStartExchangeGreenEnergyConsume_ERR:::::", err.Error())
- utils2.FilePutContents("EggEnergyStartExchangeGreenEnergyConsume_ERR", utils2.SerializeStr(map[string]interface{}{
- "body": res.Body,
- "err": err.Error(),
- }))
- _ = res.Reject(false) //TODO::拒绝 true
- var msg *md2.EggEnergyStructForStartExchangeGreenEnergy
- json.Unmarshal(res.Body, &msg)
- ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
- } else {
- err = res.Ack(true)
- fmt.Println("err ::: ", err)
- }
- } else {
- panic(errors.New("error getting message"))
- }
- }
- fmt.Println("get msg done")
- }
-
- func handleEggEnergyStartExchangeGreenEnergyConsume(msgData []byte, ch *rabbit.Channel) error {
- //1、解析mq中queue的数据结构体
- var msg *md2.EggEnergyStructForStartExchangeGreenEnergy
- err := json.Unmarshal(msgData, &msg)
- if err != nil {
- return err
- }
- engine := db.Db
-
- //2、调用制度方法
- err = egg_energy.ActivityCoinStartExchangeEggEnergy(engine, *msg, ch)
- return err
- }
|