// 运行 // [command] // mq_addr=127.0.0.1:5001 // mq_queue_name=command_queue // concurrent_num=2 func (self *CommandProcessor) Run() { // mq_addr := config.Get("command", "mq_addr") // mq_queue_name := config.Get("command", "mq_queue_name") concurrent_num := config.GetInt("command", "concurrent_num") if concurrent_num <= 0 { concurrent_num = 1 } defer self.adapter.Close() self.adapter.ReceiveCommand(func(commandStream chan Command, wg *sync.WaitGroup) { locker := make(chan bool, 4) defer close(locker) for command := range commandStream { if command == nil { continue } cmdChan := make(chan Command) defer close(cmdChan) go func(cmdChan chan Command, locker chan bool) { command := <-cmdChan self.executeCommand(command, uuid.New()) <-locker wg.Done() }(cmdChan, locker) cmdChan <- command locker <- true } }) // if err := self.mqProvider.Dial(mq_addr); err == nil { // defer self.mqProvider.Close() // if subscri, err := self.mqProvider.Subscribe(mq_queue_name); err == nil { // subscri.Receive(func(messageStream chan mq.Message, wg *sync.WaitGroup) { // locker := make(chan bool, 4) // defer close(locker) // for message := range messageStream { // if message == nil || message.GetBody() == nil { // continue // } // msgchan := make(chan mq.Message) // defer close(msgchan) // go func(msgchan chan mq.Message, locker chan bool) { // msg := <-msgchan // if command, ok := util.FromPtrValueOf(msg.GetBody()).Interface().(Command); ok { // self.executeCommand(command, msg.GetId()) // } // <-locker // wg.Done() // }(msgchan, locker) // msgchan <- message // locker <- true // } // }) // } // } suspend := make(chan bool) <-suspend }
// 新建支持Saga的领域事件 func NewSagaSupportedEvent() BaseEvent { return BaseEvent{ProcId: uuid.New()} }