蛋蛋星球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.
 
 
 
 

49 lines
1.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.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume
  17. jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume
  18. jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume
  19. jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume
  20. jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume
  21. }
  22. func Run() {
  23. for _, v := range consumeMd.RabbitMqQueueKeyList {
  24. if _, ok := jobs[v.ConsumeFunName]; ok {
  25. go doConsume(v.ConsumeFunName, *v)()
  26. }
  27. }
  28. }
  29. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  30. return func() {
  31. begin := time.Now().Local()
  32. jobs[fnName](queue)
  33. end := time.Now().Local()
  34. logx.Infof(
  35. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  36. fnName,
  37. begin.Format("2006-01-02 15:04:05.000"),
  38. end.Format("2006-01-02 15:04:05.000"),
  39. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  40. )
  41. }
  42. }