redis事件多分区消费
This commit is contained in:
parent
414ad47e72
commit
7fe6003db8
@ -152,27 +152,28 @@ func (r *RedisEventPubSub) ConsumeEvent(handler abstract.EventHandler, successCa
|
|||||||
if nil == successCallback {
|
if nil == successCallback {
|
||||||
successCallback = define.DefaultSuccessCallbackHandler
|
successCallback = define.DefaultSuccessCallbackHandler
|
||||||
}
|
}
|
||||||
go func() {
|
for partition := 0; partition < r.pubSubConfig.PartitionNum; partition++ {
|
||||||
defer func() {
|
go func(realPartition int) {
|
||||||
if panicErr := recover(); nil != panicErr {
|
defer func() {
|
||||||
fmt.Println(r)
|
if panicErr := recover(); nil != panicErr {
|
||||||
}
|
r.panicCallback(panicErr, nil, nil)
|
||||||
}()
|
}
|
||||||
for !r.isStop || (r.isStop && len(messageChan) == 0) {
|
}()
|
||||||
select {
|
for !r.isStop || (r.isStop && len(messageChan) == 0) {
|
||||||
case eventData := <-messageChan:
|
select {
|
||||||
handlerResult, handlerErr := handler(eventData)
|
case eventData := <-messageChan:
|
||||||
if nil != handlerErr {
|
handlerResult, handlerErr := handler(eventData)
|
||||||
// 失败回调
|
if nil != handlerErr {
|
||||||
failureCallback(eventData, handlerResult, handlerErr)
|
// 失败回调
|
||||||
break
|
failureCallback(eventData, handlerResult, handlerErr)
|
||||||
} else {
|
} else {
|
||||||
// 成功回调
|
// 成功回调
|
||||||
successCallback(eventData, handlerResult)
|
successCallback(eventData, handlerResult)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}(partition)
|
||||||
}()
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user