tree: 54510504b5e23c0b318518b4e34a5a002a48b7e8 [path history] [tgz]
  1. default/
  2. README.md
  3. README_zh.md
generic/README.md

Generic Invocation

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.

Getting Started

The samples of generic invocation are parted by the way of generalization:

  • default:uses MapGeneralizer which converts POJOs to maps

Each sample contains 4 subfolders:

  • go-server:Dubbo-Go server sample
  • go-client:Dubbo-Go client sample
  • java-client:Dubbo server sample
  • java-server:Dubbo client sample

Providing java samples is convenient to test interoperability between Dubbo and Dubbo-Go.

Registry

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

Server

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

Client

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

Switch the example from interface-level service discovery to application-level service discovery

  1. Modify the configuration file of the server go-server and add the field registry-type: service
registries:
     zk:
       protocol: zookeeper
       timeout: 3s
       address: 127.0.0.1:2181
       registry-type: service
...
...
  1. Modify the client.go file of client go-client

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.