🎨 逻辑完善

This commit is contained in:
李寻欢 2024-02-19 15:04:14 +08:00
parent 7caa3084c6
commit 685ce618a9

View File

@ -40,7 +40,16 @@ func Init() {
// Receive // Receive
// @description: 接收消息 // @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( if err = channel.ExchangeDeclare(
exchangeName, exchangeName,
@ -101,7 +110,7 @@ func Receive() (err error) {
msg, ok := <-messages msg, ok := <-messages
if !ok { if !ok {
log.Errorf("获取消息失败") log.Errorf("获取消息失败")
return Receive() return Receive(retryCount + 1)
} }
log.Debugf("收到消息: %s", msg.Body) log.Debugf("收到消息: %s", msg.Body)
if err = message.Message(msg.Body); err != nil { if err = message.Message(msg.Body); err != nil {