参考samples dubbo-go-samples/filter
指定filter时可用','分隔
Consumer 端
dubbo:
consumer:
filter: echo,token,tps,myCustomFilter # 可指定自定义filter
Provider 端
dubbo:
provider:
services:
GreeterProvider:
filter: myCustomFilter,echo,tps
用户可在代码中自定义 Filter,注册到框架上,并在配置中选择使用。
func init() {
extension.SetFilter("myCustomFilter", NewMyClientFilter)
}
func NewMyClientFilter() filter.Filter {
return &MyClientFilter{}
}
type MyClientFilter struct {
}
func (f *MyClientFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
fmt.Println("MyClientFilter Invoke is called, method Name = ", invocation.MethodName())
return invoker.Invoke(ctx, invocation)
}
func (f *MyClientFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, protocol protocol.Invocation) protocol.Result {
fmt.Println("MyClientFilter OnResponse is called")
return result
}