Scenarios
This article demonstrates the full process of accessing the PolarisMesh governance center hosted by the microservice engine through a demo for dubbo-go applications, helping you quickly learn how to use PolarisMesh.
Prerequisite
The local build environment has the golang environment installed and can access Github.
The system currently supports only the dubbo-go interface registration model.
Based on your business needs, resources for business deployment have been prepared. You can choose either virtual machine deployment or containerized deployment.
Operation Steps
2. On the polarismesh page under PolarisMesh, click the drop-down list in the upper left corner and select the target region.
3. Click the "ID" of the target engine to go to the basic information page.
4. View the IP address. The Dubbo-Go application accesses using the gRPC port (8091):
5. Modify the registry center address in the demo.
5.1 In the directory of the downloaded local demo source code, locate the files dubbo\\dubbo-go\\providerdubbo-goo.yaml and dubbdubbo-gogo\\consumdubbo-googo.yaml. 5.2 Add the Microservice Engine PolarisMesh IP address to the project configuration file (here taking dubbo\\dubbo-go\\provider\\dubbo-go.yaml as an example).
dubbo:
registries:
polarisMesh:
protocol: polaris
address: '10.0.4.6:8091'
namespace: default
consumer:
references:
UserProvider:
protocol: dubbo
interface: org.apache.dubbo.UserProvider.Test
UserProviderWithCustomGroupAndVersion:
protocol: dubbo
interface: org.apache.dubbo.UserProvider.Test2
version: myInterfaceVersion
6. Compile the source code into an executable program.
6.1 In the consumer and provider directories respectively, open a command prompt and run the following command to compile the project:
Compile consumer: CGO_ENABLED=0 go build -ldflags "-s -w" -o consumer
Compile provider: CGO_ENABLED=0 go build -ldflags "-s -w" -o provider
6.2 After successful compilation, two binary packages are generated as shown in Table 1.
|
dubbo3\\dubbo-go\\provider | provider | Service Provider |
dubbo3\\dubbo-go\\consumer | consumer | Service Consumer |
7. Deploy the provider and consumer microservices applications. Choose one deployment method based on your actual business needs from VM deployment and containerized deployment.
7.1 VM deployment
Upload the binary package to the Cloud Virtual Machine (CVM) instance.
Run the start command to launch:
cd /data/polaris/dubbogo_examples/provider
export DUBBO_GO_CONFIG_PATH="./dubbogo.yml"
./provider
7.2 Containerized deployment
Write the dockerfile to build the image. Refer to:
FROM golang:alpine
WORKDIR /root
ADD . /root
ENTRYPOINT ./[binary name] [startup parameters]
Deploy and run the image via TKE.
8. Verify the deployment results.
8.1 Go to the Micro PolarisMesh instance page mentioned earlier.
8.2 Choose Service Management > Service List to view the number of service instances:
If the number of instances is not zero, it indicates that the microservices engine has been successfully connected.
If the number of instances is 0 or the above service name cannot be found, it indicates that the Dubbo-Go application failed to connect to the microservice engine.
8.3 Invoke the HTTP interface of the consumer. Execute the http call, replacing ${app.port} with the listening port of the consumer (default: 18080), and ${add.address} with the exposed IP address of the consumer.
curl -L -X GET 'http://${add.address}:${app.port}/echo'
Expected return value: {"UserProvider":{"id":"A001","name":"Alex Stocks","age":18,"time":"2021-12-16T16:57:27.945+08:00"},"UserProviderWithCustomGroupAndVersion":{"id":"A001","name":"Alex Stocks from UserProviderWithCustomGroupAndVersion","age":18,"time":"2021-12-16T16:57:27.946+08:00"}}