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 938 B

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