智慧食堂-队列消费项目
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

69 satır
1.6 KiB

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