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.

init.go 1.8 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender
  22. jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans
  23. jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
  24. jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
  25. jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
  26. jobs[consumeMd.CanalMallOrdForYouMiShangFunName] = CanalMallOrdForYouMiShang
  27. jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore
  28. }
  29. func Run() {
  30. for _, v := range consumeMd.RabbitMqQueueKeyList {
  31. if _, ok := jobs[v.ConsumeFunName]; ok {
  32. go doConsume(v.ConsumeFunName, *v)()
  33. }
  34. }
  35. }
  36. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  37. return func() {
  38. begin := time.Now().Local()
  39. jobs[fnName](queue)
  40. end := time.Now().Local()
  41. logx.Infof(
  42. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  43. fnName,
  44. begin.Format("2006-01-02 15:04:05.000"),
  45. end.Format("2006-01-02 15:04:05.000"),
  46. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  47. )
  48. }
  49. }