蛋蛋星球RabbitMq消费项目
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

egg_energy_deal_user_ecpm.go 2.1 KiB

1 tydzień temu
1 tydzień temu
1 tydzień temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. utils2 "applet/app/utils"
  5. "applet/app/utils/logx"
  6. "applet/consume/md"
  7. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  8. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  9. es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
  10. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  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. "time"
  17. )
  18. func EggEnergyDealUserECPMConsume(queue md.MqQueue) {
  19. fmt.Println(">>>>>>>>>>>>EggEnergyDealUserECPMConsume>>>>>>>>>>>>")
  20. ch, err := rabbit.Cfg.Pool.GetChannel()
  21. if err != nil {
  22. logx.Error(err)
  23. return
  24. }
  25. defer ch.Release()
  26. //1、将自己绑定到交换机上
  27. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  28. //2、取出数据进行消费
  29. ch.Qos(1)
  30. delivery := ch.Consume(queue.Name, false)
  31. egg_system_rules.Init(cfg.RedisAddr)
  32. var res amqp.Delivery
  33. var ok bool
  34. for {
  35. res, ok = <-delivery
  36. if ok == true {
  37. err = handleEggEnergyDealUserECPMConsume(res.Body)
  38. if err != nil {
  39. fmt.Println("EggEnergyDealUserECPMConsume_ERR:::::", err.Error())
  40. utils2.FilePutContents("EggEnergyDealUserECPMConsume_ERR", utils2.SerializeStr(map[string]interface{}{
  41. "body": res.Body,
  42. "err": err.Error(),
  43. }))
  44. }
  45. //_ = res.Reject(false)
  46. err = res.Ack(true)
  47. fmt.Println("err ::: ", err)
  48. } else {
  49. panic(errors.New("error getting message"))
  50. }
  51. }
  52. }
  53. func handleEggEnergyDealUserECPMConsume(msgData []byte) error {
  54. //1、解析mq中queue的数据结构体
  55. var msg *md2.DealUserEcpmReq
  56. err := json.Unmarshal(msgData, &msg)
  57. if err != nil {
  58. return err
  59. }
  60. //2、更新用户信息
  61. year, week := time.Now().ISOWeek()
  62. yearStr := utils2.IntToStr(year)
  63. weekStr := utils2.IntToStr(week)
  64. index := es2.GetAppointIndexFromAlias(yearStr, weekStr)
  65. id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid)
  66. updateMap := make(map[string]interface{})
  67. updateMap["ecpm"] = utils2.StrToFloat64(msg.Ecpm)
  68. updateDocRet, err := es.UpdateDoc(index, id, updateMap)
  69. if err != nil {
  70. return err
  71. }
  72. fmt.Printf("UpdateCreateDoc ==> %+v \n\n", updateDocRet)
  73. return err
  74. }