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.
 
 
 

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