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.
 
 
 

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