This topic uses the OnlineShop demo project as an example to describe how to build a local development environment for microservices applications.

Overview of OnlineShop

OnlineShop is a microservices demo project on GitHub. The project comprises Spring Cloud and Dubbo applications. It provides complete source code and well-built container images. Therefore, it can be used as a typical example in this topic.

OnlineShop provides three microservices: Frontend, Cart Service, and Product Service. Cart Service is a shopping cart microservice implemented by a Dubbo application. Product Service is a commodity microservice implemented by a Spring Cloud application. Frontend is a client microservice used to call the Dubbo and Spring Cloud applications. The following figure shows the architecture of OnlineShop.

Architecture of OnlineShop

As shown in the figure, the project provides only the service registration and discovery capabilities. It does not support production-facilitating microservices governance capabilities such as service queries, link monitoring, configuration management, and service authentication.

In this best practice, you can learn how to seamlessly migrate OnlineShop to Enterprise Distributed Application Service (EDAS) without service discontinuity and use the full-fledged microservices governance and application monitoring capabilities provided by EDAS.

Prerequisites

A Java environment is installed.

Build a local development environment for OnlineShop

  1. Run the following command to download the source code of OnlineShop:
    git clone https://github.com/aliyun/alibabacloud-microservice-demo.git
  2. Create a project and import the content of OnlineShop.
    The OnlineShop demo files are stored in the src directory. Directory of the OnlineShop demo files
  3. Run the following command in the root directory of the project:
    mvn package -DskipTests
    If the compilation is successful, a command output similar to the following one is returned.Compiled

Create cloud resources

  1. Create a virtual private cloud (VPC). For more information, see Create an IPv4 VPC.
  2. Purchase three Elastic Compute Service (ECS) instances that can be used in the created VPC. For more information, see Create and manage an ECS instance by using the ECS console (express version)Quick start.
  3. Install Java Development Kit (JDK) and configure a Java environment on the ECS instances.
    1. Download JDK 1.8 or later and Maven 3.5 or later.
    2. Log on to each of the ECS instances. Install JDK 1.8 or later and configure the JAVA_HOME environment variable.
    3. Log on to each of the ECS instances. Install Maven 3.5 or later and configure the MAVEN_HOME environment variable.
  4. Create a Microservices Engine (MSE) instance in the VPC and record the internal endpoint of the MSE instance. For more information, see Create a Nacos engine.

Configure the registry address in the configuration files of the microservices applications

In this example, the internal endpoint of the created MSE instance that serves as a registry is mse-****-nacos-ans.mse.aliyuncs.com:8848.

  1. Open the application.properties file of each of the three microservices applications. Set the registry address to the internal endpoint of the MSE instance.
    1. Modify the registry address of the Cart Service application.
      Registry address of the Cart Service application
    2. Modify the registry address of the Product Service application.
      Registry address of the Product Service application
    3. Modify the registry address of the Frontend application.
      Registry address of the Frontend application
  2. Run the following command to compile the project:
    mvn clean install

Deploy the microservices applications on ECS instances

  1. Run the following command to upload the cartservice-provider-1.0.0-SNAPSHOT.jar package to the /tmp directory of the ECS instance on which the Cart Service application is to be deployed:
    scp src/cartservice/cartservice-provider/target/cartservice-provider-1.0.0-SNAPSHOT.jar root@XX.XX.XX.XX:/tmp
    Upload the deployment package of the Cart Service application
  2. Use SSH to log on to the ECS instance on which the Cart Service application is deployed.
    Notice You must add a security group rule that allows inbound SSH access to port 22 on the ECS instance. For more information, see Create a security group.
  3. Move the /tmp/cartservice-provider-1.0.0-SNAPSHOT.jar package to the /root directory.
  4. Run the following command to start the Cart Service application:
    nohup java -jar cartservice-provider-1.0.0-SNAPSHOT.jar &
  5. Check the nohup.out log file. If the message framed in red in the following figure is displayed, the Cart Service application is started.
    Check the nohup.out log file
  6. Repeat the preceding steps to deploy the Product Service and Frontend applications on the other two ECS instances.
  7. In the address bar of your browser, enter the endpoint of the Frontend application in the format of http://{IP address of the Frontend application}:8080/ and press the ENTER key. If the home page of the Frontend application appears, the access is successful.

Associate an Internet-facing SLB instance with the Frontend application

  1. Log on to the Server Load Balancer (SLB) console.
  2. Purchase an SLB instance in the zone in which the ECS instance for deploying the Frontend application resides. For more information, see Create a CLB instance.
  3. Find the created SLB instance on the Instances page and click Configure.
    Configure an SLB instance
  4. Set the Select Listener Protocol parameter to TCP and the Listening Port parameter to 8080.
    Configure the listening port
  5. Configure the ECS instance on which the Frontend application is deployed as the backend server. Set the port number to 8080 and configure listeners for the SLB instance as prompted.
    Configure the backend server
  6. In the address bar of your browser, enter the public endpoint of the SLB instance in the format of http://{IP address of the SLB instance}:8080/ and press the ENTER key. If the home page of the Frontend application appears, the SLB instance is associated with the Frontend application.

Send local access traffic to the Frontend application

Run the following command to keep sending local access traffic to the Frontend application:

while :
do
        result=`curl $1 -s`
        if [[ "$result" == *"500"* ]]; then
                echo `date +%F-%T` $result
        else
                echo `date +%F-%T` "success"
        fi
        sleep 0.1
done
A command output similar to the following one is returned. Send access traffic

What to do next

Smoothly migrate microservice-oriented applications to EDAS