In order to facilitate the use of Dubbogo framework users, we provide the Samples repository for user reference:
[Dubbo-go-samples warehouse address]
There are currently three ways to run dubbo-go examples:
Preconditions: docker environment is required to be ready
Below we will use “helloworld” as an example:
Start the registration center (such as zookeeper)
make -f build/Makefile docker-up
When you see output similar to the following, it means that the zookeeper server is ready to start.
> Starting dependency services with ./integrate_test/dockercompose/docker-compose.yml
Docker Compose is now in the Docker CLI, try `docker compose up`
Creating network "dockercompose_default" with the default driver
Creating dockercompose_zookeeper_1... done
Creating etcd... done
Creating nacos-standalone... done
If you want to stop the registry, you can do it by running the following command:
make -f build/Makefile docker-down
Start Service Provider
cd helloworld/go-server/cmd
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
go run .
When you see output similar to the following, the service provider is ready to start.
2021/10/27 00:33:10 Connected to 127.0.0.1:2181
2021/10/27 00:33:10 Authenticated: id=72057926938066944, timeout=10000
2021/10/27 00:33:10 Re-submitting `0` credentials after reconnect
Run service caller
cd helloworld/go-client/cmd
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
go run .
When the following information is output, it means that go-client
calls go-server
successfully.
2021-10-27T00:40:44.879+0800 DEBUG triple/dubbo3_client.go:106 TripleClient.Invoke: get reply = name:"Hello laurence" id:"12345" age:21
2021-10-27T00:40:44.879+0800 DEBUG proxy/proxy.go:218 [makeDubboCallProxy] result: name:"Hello laurence" id:"12345" age:21 , err: <nil>
2021-10-27T00:40:44.879+0800 INFO cmd/client.go:51 client response result: name:"Hello laurence" id:"12345" age:21
Integration tests
In addition to showing how to use the functions and features in dubbo-go, this project dubbo-go-samples is also used for integration testing of apache/dubbo-go. Integration tests designed for go-server
can be run as follows:
Start the server first
cd helloworld/go-server/cmd
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
go run .
Then switch to the single test directory, set the environment variables, and then execute the single test
cd integrate_test/helloworld/tests/integration
export DUBBO_GO_CONFIG_PATH="../../../../helloworld/go-client/conf/dubbogo.yml"
go test -v
When the following information is output, the integration test has passed.
> Running integration test for application go-server
...
--- PASS: TestSayHello (0.01s)
PASS
ok github.com/apache/dubbo-go-samples/integrate_test/helloworld/tests/integration0.119s
Close and Cleanup
make -f build/Makefile clean docker-down
*The following two modes of operation are related to the IDE. Here we take Intellij GoLand as an example to discuss. *
Once you open this project in GoLand, you can find that in the “Run Configuration” pop-up menu, there are already a series of pre-configured options for running related service providers and callers, for example: “helloworld-go-server " and “helloworld-go-client”.
You can select any of these quick start related examples. Of course, before running, it is assumed that the required registry has been started in advance, otherwise the use case will fail. You can choose to start it manually, or use the “docker-compose.yml” provided in the project to start the docker instance in the registration center.
Take Intellij GoLand as an example here. After opening the dubbo-go-samples project in GoLand, follow the steps below to run/debug this sample:
Start the zookeeper server
Open the “integrate_test/dockercompose/docker-compose.yml” file, and click the ▶︎▶︎ icon in the left gutter column of the editor to run, the “Service” Tab should pop up and output a text message similar to the following:
Deploying 'Compose: docker'...
/usr/local/bin/docker-compose -f ...integrate_test/dockercompose/docker-compose.yml up -d
Creating network "docker_default" with the default driver
Creating docker_zookeeper_1...
'Compose: docker' has been deployed successfully.
Start Service Provider
Open the “helloworld/go-server/cmd/server.go” file, then click the ▶︎ icon next to the “main” function in the left gutter column, and select “Modify Run Configuration…” from the pop-up menu, And make sure the following configuration is accurate:
In this way, the server in the example is ready and ready to run.
Run Service Consumer
Open the “helloworld/go-client/cmd/client.go” file, then click the ▶︎ icon next to the “main” function from the left gutter column, and then select “Modify Run Configuration… “, and make sure the following configuration is accurate:
Then you can run and call the remote service. If the call is successful, there will be the following output:
[2021-02-03/16:19:30 main.main: client.go: 66] response result: &{A001 Alex Stocks 18 2020-02-04 16:19:30.422 +0800 CST}
If you need to debug this example or the dubbo-go framework, you can switch from “Run” to “Debug” in the IDE. If you want to end, just click ◼︎ directly.