golang 的 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.
 
 
 

77 lines
2.7 KiB

  1. package consume
  2. import (
  3. "applet/app/utils/logx"
  4. consumeMd "applet/consume/md"
  5. "time"
  6. )
  7. var (
  8. jobs = map[string]func(consumeMd.MqQueue){}
  9. )
  10. func Init() {
  11. // 初始化任务列表
  12. initConsumes()
  13. }
  14. // 增加消费任务队列
  15. func initConsumes() {
  16. //jobs[consumeMd.ZhiosAcquisitionConditionDevFunName] = ZhiosAcquisitionCondition
  17. jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition
  18. jobs[consumeMd.CanalOrderConsumeFunName] = CanalOrderConsume
  19. jobs[consumeMd.CanalGuideOrderConsumeFunName] = CanalGuideOrderConsume
  20. jobs[consumeMd.ZhiOsUserVisitIpAddressConsumeFunName] = ZhiOsUserVisitIpAddressConsume
  21. jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial
  22. jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter
  23. jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender
  24. jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans
  25. jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv
  26. jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
  27. jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
  28. jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
  29. jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond
  30. //jobs[consumeMd.CanalMallOrdForYouMiShangFunName] = CanalMallOrdForYouMiShang
  31. jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore
  32. jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail
  33. jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume
  34. jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate
  35. jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate
  36. jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal
  37. jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail
  38. jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward
  39. //jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev
  40. }
  41. func Run() {
  42. for _, v := range consumeMd.RabbitMqQueueKeyList {
  43. if _, ok := jobs[v.ConsumeFunName]; ok {
  44. go doConsume(v.ConsumeFunName, *v)()
  45. }
  46. }
  47. }
  48. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  49. return func() {
  50. begin := time.Now().Local()
  51. jobs[fnName](queue)
  52. end := time.Now().Local()
  53. logx.Infof(
  54. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  55. fnName,
  56. begin.Format("2006-01-02 15:04:05.000"),
  57. end.Format("2006-01-02 15:04:05.000"),
  58. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  59. )
  60. }
  61. }