Custom service call middleware

Refer to samples dubbo-go-samples/filter

1. Preparations

2. Configure the specified Filter

When specifying a filter, it can be separated by ‘,’

  • Consumer side

    dubbo:
      consumer:
        filter: echo,token,tps,myCustomFilter # Custom filter can be specified
    
  • Provider side

    dubbo:
      provider:
        services:
          GreeterProvider:
            filter: myCustomFilter, echo, tps
    

3. Custom Filter

Users can customize Filter in the code, register it on the framework, and choose to use it in the configuration.

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
}

Last modified January 2, 2023: Enhance Dubbogo docs (#1800) (71c8e72274)