序
本文次要钻研一下 dubbo-go 的 EchoFilter
EchoFilter
dubbo-go-v1.4.2/filter/filter_impl/echo_filter.go
const (
// ECHO echo module name
ECHO = "echo"
)
func init() {extension.SetFilter(ECHO, GetFilter)
}
// EchoFilter
// RPCService need a Echo method in consumer, if you want to use EchoFilter
// eg:
// Echo func(ctx context.Context, arg interface{}, rsp *Xxx) error
type EchoFilter struct{}
- EchoFilter 没有定义属性
Invoke
dubbo-go-v1.4.2/filter/filter_impl/echo_filter.go
// Invoke ...
func (ef *EchoFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {logger.Infof("invoking echo filter.")
logger.Debugf("%v,%v", invocation.MethodName(), len(invocation.Arguments()))
if invocation.MethodName() == constant.ECHO && len(invocation.Arguments()) == 1 {
return &protocol.RPCResult{Rest: invocation.Arguments()[0],
Attrs: invocation.Attachments(),}
}
return invoker.Invoke(ctx, invocation)
}
- Invoke 办法判断 invocation.MethodName 是否是 echo,且有一个参数,是的话则返回 protocol.RPCResult
OnResponse
dubbo-go-v1.4.2/filter/filter_impl/echo_filter.go
// OnResponse ...
func (ef *EchoFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker,
_ protocol.Invocation) protocol.Result {return result}
- OnResponse 办法间接返回 result
GetFilter
dubbo-go-v1.4.2/filter/filter_impl/echo_filter.go
// GetFilter ...
func GetFilter() filter.Filter {return &EchoFilter{}
}
- GetFilter 办法创立 EchoFilter
小结
EchoFilter 的 Invoke 办法判断 invocation.MethodName 是否是 echo,且有一个参数,是的话则返回 protocol.RPCResult
doc
- echo_filter