golang 的 rabbitmq 消费项目
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

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