Quickly Experiencing Microservice Capabilities
This section uses the weathermap application as an example to describe microservice registry, discovery, service degradation, routing policy, and dark launch.
This weather forecast application displays current weather information and 5-day forecasts for regions around the world.
Step 1: Environment Preparation
1. Install JDK.
a. Check the JDK version. The JDK version must be 1.8.
b. Go to the JDK official website to download the JDK.
2. Install Node.js.
a. Check the Node.js version. The Node.js version must be later than 4.8.4.
b. Go to the Node.js official website to download the Node.js.
3. Download the weathermap application.
a. Download the weathermap service package.
b. Decompress the downloaded weathermap package and record the decompression path.
The decompression path cannot contain Chinese characters.
Step 2: Service Registry and Discovery
You have obtained the AK/SK. For details about how to obtain the AK/SK, see Managing Access Keys.
1. Go to the decompression directory of the weathermap application and open the credentials file to configure the AK/SK information and project name, and add the following information:
project=ap-southeast-1 //Project Name
2. (Optional) Configure proxy.
Go to the decompression directory of the weathermap application, open the httpproxy.properties file, and configure the proxy.
proxy.enabled=true // true: Use proxy. false: Do not use proxy.
proxy.host= // Proxy server address.
proxy.port=8080 // Proxy port number.
proxy.user= // Proxy user name.
proxy.password= // Proxy password.
#rest connect timeout setting
3. Edit the startup_all.bat script file. Add the following to line 22 and set it to the address of the microservice engine service center:
4. Run the startup_all. bat script to start all microservices.
In Windows OS, the microservice runs in the backend after being started. If you want to stop the microservice, close the process of the microservice.
5. After the application starts, log in to the Console and choose AppDev > Engine list. On the page that is displayed, click Console next to the target engine. On the Service Catalog page that is displayed, select application weathermap. Then, you can see all microservices are automatically discovered.
6. Access http://localhost:3000/.
Service Registry and Discovery.
Viewing the interface.
Step 3: Service Degradation
Service degradation predicts an error and returns a fixed value or error information. According to such a value or information, corresponding information is returned to the user.
1. Choose AppDev > Engine List. On the page that is displayed, click Console next to the target engine. On the Service Governance page that is displayed, click fusionweather to go to the governance page.
2. Click Service Degradation and then Add.
a. Select forcast and then All Methods for Service Degradation Object.
b. Select Open for Fallback Policy.
c. Click OK to save the configuration.
3. Access http://localhost:3000/, and check that the weather forecast is not displayed.
Based on the current service degradation configuration, the forecast service that accesses the fusionweather service returns an exception, and the services are disconnected. As a result, data fails to be obtained.
4. Delete the policy. Then, refresh the page and check that the application is running properly.
Setting a service degradation policy.
Accessing the interface.
Step 4: Dark Launch
Dark launch protects smooth service evolution. Through which, some service versions are open to specific objects.
1. Choose AppDev > Engine List. On the page that is displayed, click Console next to the target engine. On the Service Catalog page that is displayed, click weather to go to the governance page.
2. Choose Dark Launch and click Add a Launch Rule.
3. Perform the following operations on the displayed page:
a. Select Customization for Launch Rule.
b. Enter test in Rule Name.
c. Select 0.0.2 for Version.
d. Set Parameter Name to city and Rules to =chengdu. city is the request parameter defined in the fusionweather service.
e. Click OK to save the configuration.
4. Access http://localhost:3000/.
Based on the current dark launch rule, the weather forecast requests of Chengdu are delivered to the 0.0.2 version of the weather service. The 0.0.1 version does not contain the UV forecast, and the 0.0.2 version contains the UV forecast. Therefore, when the weather service receives a request in which city is set to chengdu, the UV forecast is displayed.
Setting dark launch.
Accessing the interface.