Repository navigation
Website content en overview mannual golang sdk sourcecode generic
Go SDK 手册(版本需核对)。原文按来源版本保留;使用前请读 版本与升级。 来源:原文 · 提交
84b35ebdab20· 返回目录
Related samples:
- Generic invocation sample: dubbo-go-samples/generic
- Triple sample: dubbo-go-samples/rpc/triple
Generic invocation in current Dubbo Go is centered on client.NewGenericService(...) and filter/generic.GenericService. Older examples based on ReferenceConfigBuilder, GenericLoad(), and GetRPCService() describe the legacy compatibility API and are no longer the recommended entry point.
The main runtime entry is in client/client.go:
genericService, err := cli.NewGenericService(
"org.apache.dubbo.samples.UserProvider",
client.WithProtocolTriple(),
client.WithSerialization(constant.Hessian2Serialization),
client.WithURL("tri://127.0.0.1:20000"),
)NewGenericService(...) does three important things by default:
- sets
NONIDL - enables generic invocation
- uses
hessian2serialization
Internally it creates filter/generic.GenericService, then wires it into the normal reference and invocation path.
The core type is:
type GenericService struct {
Invoke func(ctx context.Context, methodName string, types []string, args []hessian.Object) (any, error) `dubbo:"$invoke"`
}This mirrors the generic invocation model used by Dubbo: you provide:
- method name
- parameter type names
- argument list
and the framework sends a generic $invoke request to the remote service.
Current Dubbo Go also provides InvokeWithType(...):
var user User
err := genericService.InvokeWithType(
ctx,
"getUser",
[]string{"java.lang.String"},
[]hessian.Object{"123"},
&user,
)This helper deserializes the generic result into a concrete Go reply object. It is useful when you still want generic transport behavior but do not want to manually convert the returned map structure.
Generic invocation is usually used when:
- the caller does not have generated stubs
- the caller wants to invoke services dynamically by interface and method name
- the caller is interacting with Java Dubbo services using generic payloads
- migration or testing requires a dynamic client
For Triple plus Hessian2 compatibility scenarios, the generic sample is the best place to look first.
The implementation is not only a client helper. It is also connected to the generic filter chain under filter/generic, where Dubbo Go handles generic invocation encoding, decoding, and service-side adaptation.
That is why this feature belongs both to client APIs and to the framework's filter-based extension model.