XinYeYouKu/app/utils/mq/mqmanager.go

37 lines
742 B
Go

package mq
import (
common3 "qteam/app/constants/common"
mq "qteam/app/utils/mq/mqs"
"sync"
)
var (
MqManager = CMqManager{}
once sync.Once
)
type Imq interface {
Produce(name string, log interface{}, delayTime int, args ...interface{}) error
Consume(name string, hand interface{})
DelyConsume(name string, hand interface{})
}
type CMqManager struct {
mqs map[string]Imq
}
func (this *CMqManager) InitMq() {
this.mqs = make(map[string]Imq)
//this.mqs[common.MQ_RABBIT] = RabbitMq{}
//this.mqs[common.MQ_NSQ] = NsqMq{}
this.mqs[common3.MQ_NATS] = mq.NatsMq{}
this.mqs[common3.MQ_KFK] = mq.KafkaMq{}
}
func (this *CMqManager) GetMqByName(name string) Imq {
once.Do(func() {
this.InitMq()
})
return this.mqs[name]
}