forked from lxh/go-wxhelper
🎨 逻辑完善
This commit is contained in:
parent
7caa3084c6
commit
685ce618a9
@ -40,7 +40,16 @@ func Init() {
|
||||
|
||||
// Receive
|
||||
// @description: 接收消息
|
||||
func Receive() (err error) {
|
||||
func Receive(retry ...int) (err error) {
|
||||
var retryCount int
|
||||
if len(retry) > 0 {
|
||||
retryCount = retry[0]
|
||||
}
|
||||
// 重试次数超过100次,退出
|
||||
if retryCount > 100 {
|
||||
log.Panicf("获取消息失败次数过多")
|
||||
}
|
||||
|
||||
// 创建交换机
|
||||
if err = channel.ExchangeDeclare(
|
||||
exchangeName,
|
||||
@ -101,7 +110,7 @@ func Receive() (err error) {
|
||||
msg, ok := <-messages
|
||||
if !ok {
|
||||
log.Errorf("获取消息失败")
|
||||
return Receive()
|
||||
return Receive(retryCount + 1)
|
||||
}
|
||||
log.Debugf("收到消息: %s", msg.Body)
|
||||
if err = message.Message(msg.Body); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user