How do we make service updates or stop processes imperceptibly to consumers when using online applications? This can be done through graceful disconnection. Graceful disconnection can be implemented by modifying related container or framework configurations or deploying applications to Enterprise Distributed Application Service (EDAS) for lifecycle management. This topic describes how to implement graceful disconnection for Spring Cloud applications.

Background

How do we ensure the normal processing of consumer service requests during the period from when applications are stopped to when services are recovered? The most secure and reliable solution is to update your application when no service requests exist. However, in practice, service requests typically exist even when the application is disconnected. A traditional solution is to manually perform three steps: (1) Manually extract traffic. (2) Stop the application. (3) Update your application and then restart it. These manual operations ensure that the update process is imperceptible to clients.

An automatic mechanism can be provided at the container or framework level to manually extract traffic and process received requests. This makes the update process imperceptible to services and improves the O&M efficiency. This mechanism is called graceful disconnection.

EDAS integrates graceful disconnection into the publishing process so that graceful disconnection is automatically implemented when you stop, deploy, roll back, scale in, and reset the applications in Elastic Compute Service (ECS) clusters of EDAS.

Graceful disconnection for open-source Spring Cloud applications

This section describes how to configure open-source Spring Cloud applications to support graceful disconnection.

  1. Providers deregister services.

    ServiceRegistryEndpoint in Spring Cloud Commons provides the service deregistration function, which sends a request to control service disconnection through endpoints.

    curl -X "POST" "http://{ip}:{port}/actuator/service-registry?status=DOWN" -H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"

    When service disconnection is controlled through endpoints, the class-related method setStatus(R registration, String status) that implements ServiceRegistry is called to deregister provided services from registries.

  2. Consumers update the provider list.

    After services are deregistered from registries, consumers remove the deregistered providers from the subsequently requested provider list. For open-source Spring Cloud applications, load balancing is typically implemented by Ribbon. The following procedure shows how to modify the Ribbon update time.

    The default Ribbon update time is 30s, indicating that a deregistered provider is removed from the provider list 30s after deregistration. You can set the update time to a smaller value to make the provider list update faster. For example, you can set the update time to 2,000 ms as follows.

    ribbon.ServerListRefreshInterval=2000                        
  3. Stop the provider application.
    You can stop an application without service impact when the provider no longer receives new requests and all requests received before service deregistration have been processed.

Graceful disconnection for Spring Cloud applications in EDAS

In the preceding solution of graceful disconnection for open-source Spring Cloud applications, ServiceRegistryEndpoint is called based on the Spring Boot Actuator dependency, which is accessible only after security configuration is added. Spring Boot 1 and Spring Boot 2 have different Actuator addresses.

To t1838890.dita#Task72618, change the configured dependency to Nacos Server. When you stop an application in EDAS, EDAS removes the related provider from the service registry. This requires neither additional configuration for the application nor the Spring Boot Actuator dependency. You only need to set the provider list update time to a value less than 3s. The following describes how to perform graceful disconnection in EDAS.

  1. Log on to the EDAS console. In the upper-left corner, select a region.
  2. In the left-side navigation pane, choose Application Management > Applications. On the Applications page, click the name of the Spring Cloud application in the ECS cluster.
  3. On the Application Details page, perform the following operations to trigger graceful disconnection for Spring Cloud applications in EDAS.
    • In the upper-right corner, click Stop Application, Deploy Application, or Roll Back Application.
    • After the application is stopped, click Process Instances in Batch on the right side of the page. On the Process Instances in Batch page, select the application that you want to scale in and click Batch Scale In.
    • On the Instance Information tab, find the application instance and click Reset in the Actions column.
  4. In the upper-left corner of the Application Details page, the message A change process is being executed for this application. Status: Executing appears. Click View Details on the right of the message.
  5. On the View Details page, view the change record on graceful disconnection.
    1. Services are deregistered from the Nacos registry during the smooth application disconnection phase, which is displayed in the application change order.
    2. By default, the application is stopped 3s after services are deregistered.