蛋蛋星球RabbitMq消费项目
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

egg_slow_auto_up_lv_consume.go 1.4 KiB

1 주 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/utils"
  6. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  7. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
  8. "applet/app/utils/logx"
  9. "applet/consume/md"
  10. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  11. "encoding/json"
  12. "errors"
  13. "fmt"
  14. "github.com/streadway/amqp"
  15. "time"
  16. )
  17. func EggSlowAutoUpLvConsume(queue md.MqQueue) {
  18. fmt.Println(">>>>>>>>>>>>EggSlowAutoUpLvConsume>>>>>>>>>>>>")
  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 = handleEggSlowAutoUpLvConsume(res.Body)
  37. err = res.Ack(true)
  38. fmt.Println("err ::: ", err)
  39. } else {
  40. panic(errors.New("error getting message"))
  41. }
  42. }
  43. fmt.Println("get msg done")
  44. }
  45. func handleEggSlowAutoUpLvConsume(msgData []byte) error {
  46. time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒
  47. // 1.解析mq中queue的数据结构体
  48. var msg *md.CommUserId
  49. err := json.Unmarshal(msgData, &msg)
  50. if err != nil {
  51. return err
  52. }
  53. rule.UserUpgradeInsert(db.Db, utils.StrToInt(msg.Uid))
  54. return nil
  55. }