sequence

This paper mainly studies EchoFilter of Dubo-Go

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{}
Copy the code
  • EchoFilter does not define attributes

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)
}
Copy the code
  • The Invoke method checks if the Invocation.MethodName is echo and has one argument, if so returns 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
}
Copy the code
  • The OnResponse method returns result directly

GetFilter

Dubbo – go – v1.4.2 / filter/filter_impl echo_filter. Go

// GetFilter ...
func GetFilter() filter.Filter {
	return &EchoFilter{}
}
Copy the code
  • The GetFilter method creates an EchoFilter

summary

The Invoke method of EchoFilter determines whether the Invocation.MethodName is Echo and has one argument, if so returns protocol.rpcresult

doc

  • echo_filter