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.
 
 
 

54 lines
1.8 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.ZhiosOrderTrackUpdateForTbConsumeFunName] = ZhiosOrderTrackUpdateForTbConsume //淘宝-更新订单
  17. //jobs[consumeMd.ZhiosOrderTrackCreateForTbConsumeFunName] = ZhiosOrderTrackCreateForTbConsume //淘宝-创建订单
  18. //jobs[consumeMd.ZhiosOrderTrackRefundForTbAllConsumeFunName] = ZhiosOrderTrackRefundForTbAllConsume //淘宝-全部退款
  19. //jobs[consumeMd.ZhiosOrderTrackRefundForTbPartConsumeFunName] = ZhiosOrderTrackRefundForTbPartConsume //淘宝-部分退款
  20. jobs[consumeMd.ZhiosOrderTrackCreateForJdConsumeFunName] = ZhiosOrderTrackCreateForJdConsume //京东-创建订单
  21. jobs[consumeMd.ZhiosOrderTrackUpdateForJdConsumeFunName] = ZhiosOrderTrackUpdateForJdConsume //京东-更新订单
  22. jobs[consumeMd.ZhiosOrderTrackCreateForPddConsumeFunName] = ZhiosOrderTrackCreateForPddConsume //拼多多-全部订单
  23. jobs[consumeMd.ZhiosOrderTrackCreateForTikTokTeamConsumeFunName] = ZhiosOrderTrackCreateForTikTokTeamConsume //抖音团长服务费-全部订单
  24. }
  25. func Run() {
  26. for _, v := range consumeMd.RabbitMqQueueKeyList {
  27. if _, ok := jobs[v.ConsumeFunName]; ok {
  28. go doConsume(v.ConsumeFunName, *v)()
  29. }
  30. }
  31. }
  32. func doConsume(fnName string, queue consumeMd.MqQueue) func() {
  33. return func() {
  34. begin := time.Now().Local()
  35. jobs[fnName](queue)
  36. end := time.Now().Local()
  37. logx.Infof(
  38. "[%s] AutoConsume started at <%s>, ended at <%s> duration <%s>",
  39. fnName,
  40. begin.Format("2006-01-02 15:04:05.000"),
  41. end.Format("2006-01-02 15:04:05.000"),
  42. time.Duration(end.UnixNano()-begin.UnixNano()).String(),
  43. )
  44. }
  45. }