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.1 KiB

8 months ago
5 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ////////////////////////////////////// order_statistics /////////////////////////////////////////////////////
  17. jobs[consumeMd.CanalGuideOrderForStatistics] = CanalGuideOrderForStatistics
  18. jobs[consumeMd.CanalFinWithdrawApplyForStatistics] = CanalFinWithdrawApplyForStatistics
  19. }
  20. func Run() {
  21. for _, v := range consumeMd.RabbitMqQueueKeyList {
  22. if _, ok := jobs[v.ConsumeFunName]; ok {
  23. go doConsume(v.ConsumeFunName, *v)()
  24. }
  25. }
  26. }
  27. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  28. return func() {
  29. begin := time.Now().Local()
  30. jobs[fnName](queue)
  31. end := time.Now().Local()
  32. logx.Infof(
  33. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  34. fnName,
  35. begin.Format("2006-01-02 15:04:05.000"),
  36. end.Format("2006-01-02 15:04:05.000"),
  37. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  38. )
  39. }
  40. }