fallback

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package fallback ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPolicyValid

func IsPolicyValid(p *Policy) bool

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

func ErrorFallback(ef Func) *Policy

ErrorFallback is to build fallback policy for error.

func NewFallbackPolicy

func NewFallbackPolicy(fb Func) *Policy

NewFallbackPolicy is to build a fallback policy.

func TimeoutAndCBFallback

func TimeoutAndCBFallback(ef Func) *Policy

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

func (p *Policy) EnableReportAsFallback() *Policy

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)))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL