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.
 
 
 

82 lines
2.9 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.ZhiosAppreciationDevFunName] = ZhiosAppreciation
  17. jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation
  18. jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser
  19. //jobs[consumeMd.ZhiosAcquisitionConditionDevFunName] = ZhiosAcquisitionCondition
  20. jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition
  21. jobs[consumeMd.CanalOrderConsumeFunName] = CanalOrderConsume
  22. jobs[consumeMd.CanalGuideOrderConsumeFunName] = CanalGuideOrderConsume
  23. jobs[consumeMd.ZhiOsUserVisitIpAddressConsumeFunName] = ZhiOsUserVisitIpAddressConsume
  24. jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial
  25. jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter
  26. jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender
  27. jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans
  28. jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv
  29. jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
  30. jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
  31. jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
  32. jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond
  33. //jobs[consumeMd.CanalMallOrdForYouMiShangFunName] = CanalMallOrdForYouMiShang
  34. jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore
  35. jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail
  36. jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume
  37. jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate
  38. jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate
  39. jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal
  40. jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail
  41. jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward
  42. //jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev
  43. }
  44. func Run() {
  45. for _, v := range consumeMd.RabbitMqQueueKeyList {
  46. if _, ok := jobs[v.ConsumeFunName]; ok {
  47. go doConsume(v.ConsumeFunName, *v)()
  48. }
  49. }
  50. }
  51. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  52. return func() {
  53. begin := time.Now().Local()
  54. jobs[fnName](queue)
  55. end := time.Now().Local()
  56. logx.Infof(
  57. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  58. fnName,
  59. begin.Format("2006-01-02 15:04:05.000"),
  60. end.Format("2006-01-02 15:04:05.000"),
  61. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  62. )
  63. }
  64. }