This topic describes how to modify a local Dubbo project to integrate SOFARegistry.
Prerequisites
Before the local developmnent, the first step is to configure the maven settings
in order to get JAR files from SOFARegistry.
The location of
settings.xml
is as follows:- Windows OS :C:\Users\userName_XXX.m2\settings.xml
- Mac or Linux OS:/Users/userName_XXX/.m2/settings.xml
Note: For Linux or Mac OS, directory .m2 might be hid by default. You can use hot key
Command + Shift + .
for Mac OS andCtrl + H
for Linux to check it out.
The content of configuration: The address, username, and password of the
mvn.cloud.alipay.com
repository.<servers>
<server>
<id>nexus-server@public</id>
<username>${username}</username>
<password>${password}</password>
</server>
<server>
<id>nexus-server@public-snapshots</id>
<username>${username}</username>
<password>${password}</password>
</server>
<server>
<id>mirror-all</id>
<username>${username}</username>
<password>${password}</password>
</server>
</servers>
You can choose SOFAStack > Framework > Step 3, download the pre-configured settings.xml
file, and then use the file to replace the original one in the Maven installation directory ~/.m2/
.
Procedure
Introduce dependencies
Microservices can access SOFARegistry through the sofa-registry-dubbo-all
dependency or the sofa-registry-cloud-all
dependency.
- Access through the sofa-registry-dubbo-all dependency
- Access through the sofa-registry-cloud-all dependency
Access through the sofa-registry-dubbo-all dependency
- Introduce the service registry dependency. In the
pom.xml
file, add the following dependency:<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-registry-dubbo-all</artifactId>
<version>x.x.x</version>
</dependency>
- Configure the addressing parameters of the service registry. In the
application.properties
file, configure the following parameters:
Parameter description: The preceding parameters (instanceId, antvip.endpoint, access, and secret) are global configuration items of the middleware. Their values can be obtained from the Framework console. For more information, see Introducing SOFA Middleware > Middleware Global Configuration.spring.dubbo.registry.address=dsr://xxx:9003
spring.dubbo.registry.parameters[com.alipay.env]=shared
spring.dubbo.registry.parameters[com.alipay.instanceid]=Assigned instanceid
spring.dubbo.registry.parameters[com.antcloud.antvip.endpoint]=xxx
spring.dubbo.registry.parameters[com.antcloud.mw.access]=key
spring.dubbo.registry.parameters[com.antcloud.mw.secret]=value
Access through the sofa-registry-cloud-all dependency
- Introduce the
sofa-registry-cloud-all
SDK dependency. For version information, see SDK version description.<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-registry-cloud-all</artifactId>
<! -- Replace x.x.x with the latest version number of the SDK. -->
<version>x.x.x</version>
</dependency>
- Introduce the SOFATracer dependency. SOFATracer provides three access methods for the Dubbo framework. These methods respectively apply to Spring Boot 1.x, Spring Boot 2.x, and non-Spring Boot Dubbo apps. Select the corresponding SOFATracer dependency based on actual service needs.
- Spring Boot 1.x
<!-- for Spring Boot 1.X -->
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
<version>2.3.7.JST.1</version>
<exclusions>
<exclusion>
<groupId>com.alipay.sofa.common</groupId>
<artifactId>sofa-common-tools</artifactId>
</exclusion>
<exclusion>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-enterprise-dst-plugin</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alipay.sofa.common</groupId>
<artifactId>sofa-common-tools</artifactId>
<version>1.0.17</version>
</dependency>
- Spring Boot 2.x
<!-- for Spring Boot 2.X -->
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
<version>3.2.3.JST.1</version>
<exclusions>
<exclusion>
<groupId>com.alipay.sofa.common</groupId>
<artifactId>sofa-common-tools</artifactId>
</exclusion>
<exclusion>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-enterprise-dst-plugin</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alipay.sofa.common</groupId>
<artifactId>sofa-common-tools</artifactId>
<version>1.0.17</version>
</dependency>
- Not Spring Boot
- Import the SOFATracer dependency as that of Spring Boot 2.x.
- Add the following to main() function at the first line.
SofaTracerConfiguration.setProperty(SofaTracerConfiguration.JSON_FORMAT_OUTPUT, "false");
- Spring Boot 1.x
- Configure the service registry of Dubbo using dsr:
<dubbo:registry address="dsr://dsr"/>
. - Add app startup parameters in any of the following ways:
- In
dubbo.properties
, configure the following parameters:com.alipay.instanceid= // Required
com.antcloud.antvip.endpoint= // Required
com.antcloud.mw.access= // Required
com.antcloud.mw.secret= // Required
- Specify the values of JVM startup parameters:
-Dcom.alipay.instanceid= // Required
-Dcom.antcloud.antvip.endpoint= // Required
-Dcom.antcloud.mw.access= // Required
-Dcom.antcloud.mw.secret= // Required
- Specify the system environment variables:
Parameter description: The preceding parameters (instanceId, antvip.endpoint, access, and secret) are global configuration items of the middleware. Their values can be obtained from the Framework console. For more information, see Introducing SOFA Middleware > Middleware Global Configuration.SOFA_INSTANCE_ID= // Required
SOFA_ANTVIP_ENDPOINT= // Required
SOFA_ACCESS_KEY= // Required
SOFA_SECRET_KEY= // Required
- In
Deploys an application
After adding the dependencies and modifying the configurations in a local project, release the microservice to the Classic App Service (CAS) platform. For more information, see App deployment.
After releasing the app, choose Middleware > Microservice platform > Microservices > Service control and view the released service.
View logs
Access the {user.dir}/logs/tracelog/
directory to view logs.