An application can connect to Service Mesh in two ways:
Non-intrusively hijack and proxy registration, discovery, and communication traffic.
Connect to Service Mesh using the Service Mesh software development kit (SDK). The SDK proxies application registration and subscription requests and connects to the SOFA service registry.
This topic describes how three types of microservices can connect to the SOFA service registry (SOFARegistry) and register their services using the Service Mesh SDK.
SOFABoot services
Upgrade the SOFABoot dependency to the latest version.
For more information, see SOFABoot Version Guide.
<parent> <groupId>com.alipay.sofa</groupId> <artifactId>sofaboot-enterprise-dependencies</artifactId> <version>3.x.x</version> </parent>Add application startup parameters in either of the following ways:
Add the configuration to the configuration file:
Add the following configuration to the
app/web/src/main/resources/config/application.propertiesfile:com.alipay.env=shared com.alipay.instanceid= // Enter the instance ID. com.antcloud.antvip.endpoint= // Enter the AntVIP address of the environment. com.antcloud.mw.access= // Enter the AccessKey ID of your account. com.antcloud.mw.secret= // Enter the AccessKey secret of your account.NoteYou can obtain the parameter values from the scaffolding console. For more information, see Configuration items.
Specify JVM startup parameters:
NoteThis method overrides the code.
The following figure shows an example of the configuration in IntelliJ IDEA.
-Dcom.alipay.env=shared -Dcom.alipay.instanceid= // Enter the instance ID. -Dcom.antcloud.antvip.endpoint= // Enter the AntVIP address of the environment. -Dcom.antcloud.mw.access= // Enter the AccessKey ID of your account. -Dcom.antcloud.mw.secret= // Enter the AccessKey secret of your account.NoteYou can obtain the parameter values from the scaffolding console. For more information, see Configuration items.
Dubbo services
Import the
sofa-registry-cloud-allSDK dependency.For more 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>Import the Tracer dependency.
Tracer provides different dependencies for Spring Boot 1.x, Spring Boot 2.x, and non-Spring Boot Dubbo applications. Select and import the appropriate Tracer dependency based on your application type.
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>Non-Spring Boot
The Tracer dependency information is the same as that for Spring Boot 2.x. After you import the dependency, add the following statement to the first line of the main entry point in your code:
SofaTracerConfiguration.setProperty(SofaTracerConfiguration.JSON_FORMAT_OUTPUT,"false");
Configure the Dubbo registry to use dsr:
<dubbo:registry address="dsr://dsr"/>.Add application startup parameters in any of the following ways:
Add the following configuration to
dubbo.properties:com.alipay.instanceid= // Enter the instance ID. com.antcloud.antvip.endpoint= // Enter the AntVIP address of the environment. com.antcloud.mw.access= // Enter the AccessKey ID of your account. com.antcloud.mw.secret= // Enter the AccessKey secret of your account.Specify JVM startup parameters:
-Dcom.alipay.env=shared -Dcom.alipay.instanceid= // Enter the instance ID. -Dcom.antcloud.antvip.endpoint= // Enter the AntVIP address of the environment. -Dcom.antcloud.mw.access= // Enter the AccessKey ID of your account. -Dcom.antcloud.mw.secret= // Enter the AccessKey secret of your account.Specify system environment variables:
SOFA_INSTANCE_ID= // Enter the instance ID. SOFA_ANTVIP_ENDPOINT= // Enter the AntVIP address of the environment. SOFA_ACCESS_KEY= // Enter the AccessKey ID of your account. SOFA_SECRET_KEY= // Enter the AccessKey secret of your account.NoteYou can obtain the parameter values from the scaffolding console. For more information, see Configuration items.
Spring Cloud services
Import the following
sofa-registry-cloud-allSDK dependency.For more 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>Import the corresponding Tracer dependency based on your Spring Cloud version.
Camden, Dalston, and Edgware versions (for Spring Boot 1.x)
<!-- Supports log records for service invocations. --> <!-- 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>Finchley and Greenwich versions (for Spring Boot 2.x)
<!-- Connect to Tracer --> <!-- 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>
Add application startup parameters in any of the following ways.
ImportantIf your application is not published on the SOFAStack containerized application service or classic application service, you do not need to add the following parameter settings.
Specify the following parameters in the application's YAML file:
sofa: registry: discovery: instanceId: // Enter the instance ID. antcloudVip: // Enter the AntVIP address of the environment. accessKey: // Enter the AccessKey ID of your account. secretKey: // Enter the AccessKey secret of your account.Specify JVM startup parameters:
-Dcom.alipay.instanceid= // Enter the instance ID. -Dcom.antcloud.antvip.endpoint= // Enter the AntVIP address of the environment. -Dcom.antcloud.mw.access= // Enter the AccessKey ID of your account. -Dcom.antcloud.mw.secret= // Enter the AccessKey secret of your account.Specify system environment variables:
SOFA_INSTANCE_ID= // Enter the instance ID. SOFA_ANTVIP_ENDPOINT= // Enter the AntVIP address of the environment. SOFA_SECRET_KEY= // Enter the AccessKey ID of your account. SOFA_ACCESS_KEY= // Enter the AccessKey secret of your account.NoteYou can obtain the parameter values from the scaffolding console. For more information, see Configuration items.
After you modify the application locally, you can publish and deploy it to Container Application Service or Classic Application Service (Apsara Stack only). For more information, see Service publishing.