Documentation ¶
Overview ¶
Package fallback ...
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPolicyValid ¶
IsPolicyValid to check if the Fallback policy is valid.
Types ¶
type Func ¶
type Func func(ctx context.Context, args utils.KitexArgs, result utils.KitexResult, err error) (fbErr error)
Func is the definition for fallback func, which can do fallback both for error and resp. Notice !! The args and result are not the real rpc req and resp, are respectively XXXArgs and XXXResult of generated code. setup eg: client.WithFallback(fallback.NewFallbackPolicy(yourFunc))
func UnwrapHelper ¶
func UnwrapHelper(userFB RealReqRespFunc) Func
UnwrapHelper helps to get the real request and response. Therefor, the RealReqRespFunc only need to process the real rpc req and resp but not the XXXArgs and XXXResult. eg:
`client.WithFallback(fallback.NewFallbackPolicy(fallback.UnwrapHelper(yourRealReqRespFunc)))`
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy is the definition for fallback.
- fallbackFunc is fallback func.
- reportAsFallback is used to decide whether to report Metric according to the Fallback result.
func ErrorFallback ¶
ErrorFallback is to build fallback policy for error.
func NewFallbackPolicy ¶
NewFallbackPolicy is to build a fallback policy.
func TimeoutAndCBFallback ¶
TimeoutAndCBFallback is to build fallback policy for rpc timeout and circuit breaker error. Kitex will filter the errors, only timeout and circuit breaker can trigger the ErrorFunc to execute.
func (*Policy) DoIfNeeded ¶
func (p *Policy) DoIfNeeded(ctx context.Context, ri rpcinfo.RPCInfo, args, result interface{}, err error) (fbErr error, reportAsFallback bool)
DoIfNeeded do fallback
func (*Policy) EnableReportAsFallback ¶
type RealReqRespFunc ¶
type RealReqRespFunc func(ctx context.Context, req, resp interface{}, err error) (fbResp interface{}, fbErr error)
RealReqRespFunc is the definition for fallback func with real rpc req as param, and must return the real rpc resp. setup eg: client.WithFallback(fallback.TimeoutAndCBFallback(fallback.UnwrapHelper(yourRealReqRespFunc)))