蛋蛋星球RabbitMq消费项目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

egg_energy_start_exchange_green_energy.go 2.1 KiB

2 semanas atrás
2 semanas atrás
2 semanas atrás
4 dias atrás
1 semana atrás
2 semanas atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 EggEnergyStartExchangeGreenEnergyConsume(queue md.MqQueue) {
  18. fmt.Println(">>>>>>>>>>>>EggEnergyStartExchangeGreenEnergyConsume>>>>>>>>>>>>")
  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 = handleEggEnergyStartExchangeGreenEnergyConsume(res.Body, ch)
  37. if err != nil {
  38. fmt.Println("EggEnergyStartExchangeGreenEnergyConsume_ERR:::::", err.Error())
  39. utils2.FilePutContents("EggEnergyStartExchangeGreenEnergyConsume_ERR", utils2.SerializeStr(map[string]interface{}{
  40. "body": res.Body,
  41. "err": err.Error(),
  42. }))
  43. _ = res.Reject(false) //TODO::拒绝 true
  44. var msg *md2.EggEnergyStructForStartExchangeGreenEnergy
  45. json.Unmarshal(res.Body, &msg)
  46. ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
  47. } else {
  48. err = res.Ack(true)
  49. fmt.Println("err ::: ", err)
  50. }
  51. } else {
  52. panic(errors.New("error getting message"))
  53. }
  54. }
  55. fmt.Println("get msg done")
  56. }
  57. func handleEggEnergyStartExchangeGreenEnergyConsume(msgData []byte, ch *rabbit.Channel) error {
  58. //1、解析mq中queue的数据结构体
  59. var msg *md2.EggEnergyStructForStartExchangeGreenEnergy
  60. err := json.Unmarshal(msgData, &msg)
  61. if err != nil {
  62. return err
  63. }
  64. engine := db.Db
  65. //2、调用制度方法
  66. err = egg_energy.ActivityCoinStartExchangeEggEnergy(engine, *msg, ch)
  67. return err
  68. }