transfer_middleware/until/mq/recover.go

41 lines
1023 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package mq
import (
"fmt"
"github.com/apache/rocketmq-client-go/v2/primitive"
)
type Logger interface {
// Debugf logs a formatted debugging message.
Debugf(format string, args ...interface{})
// Infof logs a formatted informational message.
Infof(format string, args ...interface{})
// Warnf logs a formatted warning message.
Warnf(format string, args ...interface{})
// Errorf logs a formatted error message.
Errorf(format string, args ...interface{})
}
func init() {
SetRecoverLogger(nil)
}
// SetRecoverLogger 设置RocketMQ的recover的处理函数日志不设置会导致协程panic后程序退出
func SetRecoverLogger(logger Logger) {
SetRecoverHandler(func(err any) {
if logger == nil {
fmt.Printf("rocketmq 发生 panic%+v\n", err)
return
}
logger.Errorf("rocketmq 发生 panic%+v", err)
})
}
// SetRecoverHandler 设置RocketMQ的recover的处理函数不设置会导致协程panic后程序退出
func SetRecoverHandler(fn func(any)) {
primitive.PanicHandler = fn
}