Connecting Spring Cloud Applications to ServiceComb Engines
This section uses a demo to demonstrate how to connect a Spring Cloud application to a ServiceComb engine Using Spring Cloud Huawei SDK.
- Preparations
You need to grant permissions, create a VPC and subnet, obtain the demo package, and prepare the local host for compilation, building, and packaging.
- Creating a ServiceComb Engine
You can select engine specifications, AZs, and networks when creating an engine.
- Connecting Spring Cloud Applications to ServiceComb Engines
This section describes how to connect a provider service and a consumer service to a ServiceComb engine.
Preparations
- You have obtained an account and its password for logging in to the console.
- Grant permissions.
You must have the required permissions to create dependent resources and ServiceComb engines. For details, see Creating a User and Granting CSE Permissions.
- Create a VPC and subnet.
ServiceComb engines run in a VPC and need to be bound to a subnet. You must have a VPC and subnet to create ServiceComb engines. For details, see "Creating a VPC with a Subnet" in Virtual Private Cloud User Guide. Skip this step if you already have a VPC and subnet.
- The Java JDK and Maven have been installed on the local host for compilation, building, and packaging, and the Maven central library can be accessed.
- Download the demo source code from GitHub to the local host and decompress it.
Creating a ServiceComb Engine
- Log in to CSE.
- Choose Exclusive ServiceComb Engines > Buy ServiceComb Engine.
- Set parameters according to the following table. Parameters marked with an asterisk (*) are mandatory. For details, see Creating a ServiceComb Engine.
Table 1 Creating a ServiceComb engine Parameter
Description
*Billing Mode
Billing mode. Currently, Pay-per-use is supported. Pay-per-use is postpaid. You use ServiceComb engines and then pay as billed for your usage duration.
*Enterprise Project
Select the enterprise project where the ServiceComb engine locates. Enterprise projects let you manage cloud resources and users by project. default is selected by default.
*Instances
Select the engine specifications. In this example, select 100 microservice instances.
*Engine Type
If the engine type is cluster, the engine is deployed in cluster mode and supports host-level DR.
*Name
Enter a ServiceComb engine name. The name contains 3 to 24 characters, including letters, digits, and hyphens (-), and starts with a letter but cannot end with a hyphen (-). For example, cse-test.
*AZ
Select one or three AZs. In this example, select one AZ to provide host-level DR.
*Network
Select the created VPC and subnet. You can search for and select a VPC and subnet from the drop-down list.
Description
Click
and enter the engine description, for example, create a ServiceComb engine.*Security Authentication
The exclusive ServiceComb engine with security authentication enabled provides the system management function using the role-based access control (RBAC) through the microservice engine console. In this example, disable security authentication. You can enable it after the instance is created.
- Click Buy. The page for confirming the engine information is displayed.
- Click Submit and wait until the engine is created.
- It takes about 31 minutes to create a microservice engine.
- After the microservice engine is created, its status is Available. For details about how to view the microservice engine status, see Viewing ServiceComb Engine Information.
- If the microservice engine fails to be created, view the failure cause on the Operation page and rectify the fault. Then, you can perform the following operations:
- In the Microservice Engine Information area, click Retry to create a microservice engine again.
- If the retry fails, delete the microservice engine that fails to be created. For details, see Deleting a ServiceComb Engine.
Connecting Spring Cloud Applications to ServiceComb Engines
- Log in to CSE.
- Choose Exclusive ServiceComb Engine.
- Click the ServiceComb engine created in Creating a ServiceComb Engine.
- Obtain the service center address and configuration center address of the ServiceComb engine.
In the Service Discovery and Configuration area, you can view the service center address and configuration center address of the microservice engine.
- Change the addresses of the registry center and configuration center in the demo.
- In the directory of the demo source code downloaded to the local host, find the \basic\consumer\src\main\resources\bootstrap.yml and \basic\provider\src\main\resources\bootstrap.yml files.
- Add the service center address and configuration center address of the ServiceComb engine to the project configuration file (\basic\consumer\src\main\resources\bootstrap.yml is used as an example).
spring: application: name: basic-consumer cloud: servicecomb: discovery: enabled: true watch: false # Registry center address address: https://192.168.0.210:30100,https://192.168.0.246:30100 appName: basic-application serviceName: ${spring.application.name} version: 0.0.1 healthCheckInterval: 30 config: # Configuration center address serverType: kie serverAddr: https://192.168.0.210:30110,https://192.168.0.246:30110
In the ServiceStage deployment scenario, the service registry center and configuration center addresses are automatically injected during the deployment. You do not need to manually add them.
- Pack the demo source code into a JAR package.
- In the root directory of the demo source code, open the Command Prompt and run the mvn clean package command to package and compile the project.
- After the compilation is successful, two JAR packages are generated, as shown in Table 2.
- Deploy the application.
Deploy provider and consumer on ServiceStage.
- Upload the JAR package generated in 6 to OBS.
- Create a CCE cluster in the same VPC as the ServiceComb engine instance. For details, see "Creating a Kubernetes Cluster" in Cloud Container Engine User Guide.
- Create a ServiceStage environment in the VPC where the engine instance is located, and manage the ServiceComb engine and CCE resource. For details, see "Creating an Environment" in ServiceStage User Guide.
- Deploy provider and consumer. For details, see "Creating and Deploying a Component" in ServiceStage User Guide.
- Confirm the deployment results.
- Optional: On the CSE console, choose Exclusive ServiceComb Engine and click the ServiceComb engine created in Creating a ServiceComb Engine.
- Choose Microservice Catalog > Microservice List to view the number of basic-consumer and basic-provider microservice instances.
- If Instances is not 0, the demo has been connected to the ServiceComb engine.
- If Instances is 0 or the basic-consumer and basic-provider services cannot be found, the demo fails to be connected to the microservice engine.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot