Use SOFARegistry with Dubbo

更新时间:
复制 MD 格式

This topic describes how to modify a local Dubbo project to connect to the SOFARegistry service registry.

Prerequisites

Before you start, you must configure the JAR package repository in your local Maven settings. This allows your project to download the service registry's JAR packages from the repository through Maven. The configuration is as follows:

  • Configuration path:

    • For Windows: C:\Users\userName_XXX\.m2\settings.xml

    • For macOS or Linux: /Users/userName_XXX/.m2/settings.xml

      Important

      On Linux and macOS, the .m2 folder may be hidden. On macOS, press Command + Shift + . to display it. On Linux, press Ctrl + H to display it.

  • Configuration details:

    1. Configure the address, username, and password for the mvn.cloud.alipay.com repository.

      The following example shows the configuration:

      <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>
    2. Update the mirror configuration for the development environment. This step is optional and is only required if you cannot download JAR packages locally.

      If the mirror in your local Maven settings.xml file (default path: ~/.m2/settings.xml) is set to *, you must exclude the alipay-cloud-server@public repository, as shown in the following example:

      <mirror>
          <id>nexus-aliyun</id>
          <!-- <mirrorOf>*</mirrorOf> -->
         <mirrorOf>*,!alipay-cloud-server@public</mirrorOf>
          <name>Nexus aliyun</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>

      Change the mirrorOf setting from * to *,!alipay-cloud-server@public. This excludes the alipay-cloud-server@public repository from the mirror.

Alternatively, you can download a pre-configured settings.xml file from the Scaffolding console. Then, navigate to the previously mentioned configuration path and use this file to overwrite the existing settings.xml file.settings

Procedure

  1. Develop the application locally.

    1. Add the repository address.

      To ensure that the SDK and its corresponding tracer package can be downloaded, add the repository address to the root pom.xml file of your project:

      <repositories>
        <repository>
          <id>alipay-cloud-server@public</id>
          <url>http://mvn.cloud.alipay.com/nexus/content/groups/open</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
    2. In the root pom.xml file of your project, import the sofa-registry-cloud-all SDK dependency.

      For version information, see SDK Version Guide.

      <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>
      Note

      • Version 1.2.8 of the sofa-registry-cloud-all SDK is compatible with all current versions of Dubbo applications.

      • If you imported the SDK dependency using sofa-registry-dubbo-all, you can directly upgrade it to the sofa-registry-cloud-all dependency.

    3. Import the Tracer dependency.

      Tracer provides the following three connection types based on your Dubbo application framework version. Choose the type that is appropriate for your application.

      • 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>
      • For Dubbo applications that do not use Spring Boot.

        1. Import the same dependency as for Spring Boot 2.x.

        2. In your code, add the following switch to the first line of the main method:

          SofaTracerConfiguration.setProperty(SofaTracerConfiguration.JSON_FORMAT_OUTPUT,"false");
    4. Configure the Dubbo service registry.

      Use dsr: <dubbo:registry address="dsr://dsr"/>.

    5. Add application startup parameters.

      You can add them in any of the following ways:

      • Configure the following properties in the dubbo.properties file:

        Note

        The default path is dubbo.properties in the root directory of the classpath. You can also manually specify the path using the JVM parameter -Ddubbo.properties.file=xxx.properties.

        com.alipay.instanceid=                   // The instance ID of the current account.
        com.antcloud.antvip.endpoint=     // The AntVIP address value for the current region.
        com.antcloud.mw.access=              // The AccessKey ID of the current account.
        com.antcloud.mw.secret=               // The AccessKey secret of the current account.

        Image 1

      • Specify JVM startup parameter values:

        -Dcom.alipay.instanceid=                  // The instance ID of the current account.
        -Dcom.antcloud.antvip.endpoint=    // The AntVIP address value for the current region.
        -Dcom.antcloud.mw.access=             // The AccessKey ID of the current account.
        -Dcom.antcloud.mw.secret=             // The AccessKey secret of the current account.
      • Specify system environment variables:

        SOFA_INSTANCE_ID=                    // The instance ID of the current account.
        SOFA_ANTVIP_ENDPOINT=          // The AntVIP address value for the current region.
        SOFA_ACCESS_KEY=                      // The AccessKey ID of the current account.
        SOFA_SECRET_KEY=                     // The AccessKey secret of the current account.
      Note

      The preceding parameter values are global middleware configuration items. You can obtain them from the Scaffolding console. For more information, see Configuration guide.

  2. Publish the application.

    1. Log on to the SOFAStack console.

    2. In the navigation pane on the left, choose Operations Management > Classic Application Service > Application Publishing > Release Ticket. Then, create and execute a release ticket.

      For more information, see Create and execute a release ticket. After the application is published, you can view the service. In the navigation pane on the left, choose Middleware > Microservice Platform > Microservices > Service Management. The published service is displayed on the Service Management page.SOFARegistry 架构图

View logs

You can view the service registry logs in /home/admin/logs/registry.

Note

If you are using an older client runtime mode, view the logs in /home/admin/logs/confreg.