All Products
Search
Document Center

How is SOFARegistry used by Dubbo?

Last Updated: Aug 17, 2020

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 and Ctrl + H for Linux to check it out.

  • The content of configuration: The address, username, and password of the mvn.cloud.alipay.com repository.

    1. <servers>
    2. <server>
    3. <id>nexus-server@public</id>
    4. <username>${username}</username>
    5. <password>${password}</password>
    6. </server>
    7. <server>
    8. <id>nexus-server@public-snapshots</id>
    9. <username>${username}</username>
    10. <password>${password}</password>
    11. </server>
    12. <server>
    13. <id>mirror-all</id>
    14. <username>${username}</username>
    15. <password>${password}</password>
    16. </server>
    17. </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

  1. Introduce the service registry dependency. In the pom.xml file, add the following dependency:
    1. <dependency>
    2. <groupId>com.alipay.sofa</groupId>
    3. <artifactId>sofa-registry-dubbo-all</artifactId>
    4. <version>x.x.x</version>
    5. </dependency>
  2. Configure the addressing parameters of the service registry. In the application.properties file, configure the following parameters:
    1. spring.dubbo.registry.address=dsr://xxx:9003
    2. spring.dubbo.registry.parameters[com.alipay.env]=shared
    3. spring.dubbo.registry.parameters[com.alipay.instanceid]=Assigned instanceid
    4. spring.dubbo.registry.parameters[com.antcloud.antvip.endpoint]=xxx
    5. spring.dubbo.registry.parameters[com.antcloud.mw.access]=key
    6. spring.dubbo.registry.parameters[com.antcloud.mw.secret]=value
    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.

Access through the sofa-registry-cloud-all dependency

  1. Introduce the sofa-registry-cloud-all SDK dependency. For version information, see SDK version description.
    1. <dependency>
    2. <groupId>com.alipay.sofa</groupId>
    3. <artifactId>sofa-registry-cloud-all</artifactId>
    4. <! -- Replace x.x.x with the latest version number of the SDK. -->
    5. <version>x.x.x</version>
    6. </dependency>
  2. 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
      1. <!-- for Spring Boot 1.X -->
      2. <dependency>
      3. <groupId>com.alipay.sofa</groupId>
      4. <artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
      5. <version>2.3.7.JST.1</version>
      6. <exclusions>
      7. <exclusion>
      8. <groupId>com.alipay.sofa.common</groupId>
      9. <artifactId>sofa-common-tools</artifactId>
      10. </exclusion>
      11. <exclusion>
      12. <groupId>com.alipay.sofa</groupId>
      13. <artifactId>tracer-enterprise-dst-plugin</artifactId>
      14. </exclusion>
      15. </exclusions>
      16. </dependency>
      17. <dependency>
      18. <groupId>com.alipay.sofa.common</groupId>
      19. <artifactId>sofa-common-tools</artifactId>
      20. <version>1.0.17</version>
      21. </dependency>
    • Spring Boot 2.x
      1. <!-- for Spring Boot 2.X -->
      2. <dependency>
      3. <groupId>com.alipay.sofa</groupId>
      4. <artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
      5. <version>3.2.3.JST.1</version>
      6. <exclusions>
      7. <exclusion>
      8. <groupId>com.alipay.sofa.common</groupId>
      9. <artifactId>sofa-common-tools</artifactId>
      10. </exclusion>
      11. <exclusion>
      12. <groupId>com.alipay.sofa</groupId>
      13. <artifactId>tracer-enterprise-dst-plugin</artifactId>
      14. </exclusion>
      15. </exclusions>
      16. </dependency>
      17. <dependency>
      18. <groupId>com.alipay.sofa.common</groupId>
      19. <artifactId>sofa-common-tools</artifactId>
      20. <version>1.0.17</version>
      21. </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.
        1. SofaTracerConfiguration.setProperty(SofaTracerConfiguration.JSON_FORMAT_OUTPUT, "false");
  3. Configure the service registry of Dubbo using dsr: <dubbo:registry address="dsr://dsr"/>.
  4. Add app startup parameters in any of the following ways:
    • In dubbo.properties, configure the following parameters:
      1. com.alipay.instanceid= // Required
      2. com.antcloud.antvip.endpoint= // Required
      3. com.antcloud.mw.access= // Required
      4. com.antcloud.mw.secret= // Required
    • Specify the values of JVM startup parameters:
      1. -Dcom.alipay.instanceid= // Required
      2. -Dcom.antcloud.antvip.endpoint= // Required
      3. -Dcom.antcloud.mw.access= // Required
      4. -Dcom.antcloud.mw.secret= // Required
    • Specify the system environment variables:
      1. SOFA_INSTANCE_ID= // Required
      2. SOFA_ANTVIP_ENDPOINT= // Required
      3. SOFA_ACCESS_KEY= // Required
      4. SOFA_SECRET_KEY= // Required
      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.

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.