All Products
Search
Document Center

How is SOFARegistry used by Spring Cloud?

Last Updated: Aug 17, 2020

This topic describes how to modify a local Spring Cloud project and connect it to 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 to access the console page, download the preconfigured settings.xml file, and copy it to the Maven installation directory ~/.m2/ to replace the existing configuration file.

Procedure

Develop an app

  1. Import the following 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. Import the corresponding SOFATracer dependency based on the Spring Cloud version.
    • Spring Cloud: Camden, Dalston, and Edgware versions (corresponding to Spring Boot 1.x)
      1. <!-- Services can call the logging capability of SOFATracer. -->
      2. <!-- for Spring Boot 1.X -->
      3. <dependency>
      4. <groupId>com.alipay.sofa</groupId>
      5. <artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
      6. <version>2.3.7.JST.1</version>
      7. <exclusions>
      8. <exclusion>
      9. <groupId>com.alipay.sofa.common</groupId>
      10. <artifactId>sofa-common-tools</artifactId>
      11. </exclusion>
      12. <exclusion>
      13. <groupId>com.alipay.sofa</groupId>
      14. <artifactId>tracer-enterprise-dst-plugin</artifactId>
      15. </exclusion>
      16. </exclusions>
      17. </dependency>
      18. <dependency>
      19. <groupId>com.alipay.sofa.common</groupId>
      20. <artifactId>sofa-common-tools</artifactId>
      21. <version>1.0.17</version>
      22. </dependency>
    • Spring Cloud: Finchley and Greenwich versions (corresponding to Spring Boot 2.x)
      1. <! -- Access SOFATracer. -->
      2. <!-- for Spring Boot 2.X -->
      3. <dependency>
      4. <groupId>com.alipay.sofa</groupId>
      5. <artifactId>tracer-enterprise-sofa-boot-starter</artifactId>
      6. <version>3.2.3.JST.1</version>
      7. <exclusions>
      8. <exclusion>
      9. <groupId>com.alipay.sofa.common</groupId>
      10. <artifactId>sofa-common-tools</artifactId>
      11. </exclusion>
      12. <exclusion>
      13. <groupId>com.alipay.sofa</groupId>
      14. <artifactId>tracer-enterprise-dst-plugin</artifactId>
      15. </exclusion>
      16. </exclusions>
      17. </dependency>
      18. <dependency>
      19. <groupId>com.alipay.sofa.common</groupId>
      20. <artifactId>sofa-common-tools</artifactId>
      21. <version>1.0.17</version>
      22. </dependency>
  3. Add app startup parameters in any of the following ways.

    Note: To publish the app on platforms other than Container App Service or Classic Application Service provided by SOFAStack, the following parameter configurations do not need to be added.

    • In the YML file of the app, specify the parameters:
      1. sofa:
      2. registry:
      3. discovery:
      4. instanceId: // Required
      5. antcloudVip: // Required
      6. accessKey: // Required
      7. secretKey: // 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=
      2. SOFA_ANTVIP_ENDPOINT=
      3. SOFA_SECRET_KEY=
      4. SOFA_ACCESS_KEY=
      Parameter description: The preceding parameters (instanceId, antcloudVip, accessKey, and secretKey) are global configuration items of the middleware. Their values can be obtained from the scaffolding console. For more information, see Introduce SOFA Middleware > Middleware Global Configuration.

Deploy an app

Note: If you need to publish an app on platforms other than Container App Service or Classic Application Service provided by SOFAStack, see the help document of the corresponding platform.

  1. Publish your app on Classic Application Service. For more information, see Deploy an application.
  2. After publishing the app, choose Middleware > Microservice Platform > Microservices > Service Control to access the console page and view the published service.

View logs

View logs in the {user.dir}/logs/tracelog directory or {user.dir}/logs/spring.log.