Generic invocation ensures the RPC could be passed properly even if one of clients has no information about interface, because generic invocation converts the POJO to a generic type, like dictionary, string, etc. It is often used for testing and gateways. Please visit our documentation for more details.
The samples of generic invocation are parted by the way of generalization:
Each sample contains 4 subfolders:
Providing java samples is convenient to test interoperability between Dubbo and Dubbo-Go.
This sample uses ZooKeeper as the registry. In fact, etcd and Nacos are supported as well. Executing the following command, a ZooKeeper instance will be launched. Please note that docker and docker-compose SHOULD be installed before.
cd ./default/go-server/docker \ && docker-compose up -d
There are two ways to launch a Dubbo-Go server: using GoLand or using command line tool.
Using GoLand. Please select v3config-generic/generic-default-go-server from Configurations at top-right corner, and then click Run button.
Using command line tool. The $ProjectRootDir is the root directory of the dubbo-go-samples project.
cd $ProjectRootDir/generic/default/go-server/cmd \ && go run server.go
There are two ways to launch a Dubbo-Go client: using GoLand or using command line tool.
Using GoLand. Please select v3config-generic/generic-default-go-client from Configurations at top-right corner, and then click Run button.
Using command line tool. The $ProjectRootDir is the root directory of the dubbo-go-samples project.
cd $ProjectRootDir/generic/default/go-client/cmd \ && go run client.go
registry-type: serviceregistries:
zk:
protocol: zookeeper
timeout: 3s
address: 127.0.0.1:2181
registry-type: service
...
...
First add the field RegistryType: "service":
registryConfig := &config.RegistryConfig{
Protocol: "zookeeper",
Address: "127.0.0.1:2181",
RegistryType: "service",
}
Then add metadataConfig configuration:
metadataConf := &config.MetadataReportConfig{
Protocol: "zookeeper",
Address: "127.0.0.1:2181",
}
Finally, configure metadataConfig into rootConfig through SetMetadataReport
...
...
rootConfig := config. NewRootConfigBuilder().
AddRegistry("zk", registryConfig).
SetMetadataReport(metadataConf).
build()
...
...
Now, the generic call of application-level service discovery can be realized.