golang 的 rabbitmq 消费项目
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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