蛋蛋星球RabbitMq消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

egg_energy_auto_exchange_green_energy.go 1.9 KiB

3 weeks ago
3 weeks ago
3 weeks ago
2 weeks ago
3 weeks ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. utils2 "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "applet/consume/md"
  8. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy"
  10. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  11. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  12. "encoding/json"
  13. "errors"
  14. "fmt"
  15. "github.com/streadway/amqp"
  16. )
  17. func EggEnergyAutoExchangeGreenEnergyConsume(queue md.MqQueue) {
  18. fmt.Println(">>>>>>>>>>>>EggEnergyAutoExchangeGreenEnergyConsume>>>>>>>>>>>>")
  19. ch, err := rabbit.Cfg.Pool.GetChannel()
  20. if err != nil {
  21. logx.Error(err)
  22. return
  23. }
  24. defer ch.Release()
  25. //1、将自己绑定到交换机上
  26. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  27. //2、取出数据进行消费
  28. ch.Qos(1)
  29. delivery := ch.Consume(queue.Name, false)
  30. egg_system_rules.Init(cfg.RedisAddr)
  31. var res amqp.Delivery
  32. var ok bool
  33. for {
  34. res, ok = <-delivery
  35. if ok == true {
  36. err = handleEggEnergyAutoExchangeGreenEnergyConsume(res.Body)
  37. if err != nil {
  38. fmt.Println("EggEnergyAutoExchangeGreenEnergyConsume_ERR:::::", err.Error())
  39. utils2.FilePutContents("EggEnergyAutoExchangeGreenEnergyConsume_ERR", utils2.SerializeStr(map[string]interface{}{
  40. "body": res.Body,
  41. "err": err.Error(),
  42. }))
  43. _ = res.Reject(true) //TODO::拒绝
  44. } else {
  45. err = res.Ack(true)
  46. fmt.Println("err ::: ", err)
  47. }
  48. } else {
  49. panic(errors.New("error getting message"))
  50. }
  51. }
  52. fmt.Println("get msg done")
  53. }
  54. func handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte) error {
  55. //1、解析mq中queue的数据结构体
  56. var msg *md2.EggEnergyStructForAutoExchangeGreenEnergy
  57. err := json.Unmarshal(msgData, &msg)
  58. if err != nil {
  59. return err
  60. }
  61. engine := db.Db
  62. //2、调用制度方法
  63. err = egg_energy.ActivityCoinAutoExchangeEggPersonEnergy(engine, *msg)
  64. return err
  65. }