Help Center/ Cloud Application Engine/ Best Practices/ Graceful Startup of a Spring Cloud Application
Updated on 2024-05-25 GMT+08:00

Graceful Startup of a Spring Cloud Application

Overview

This section describes how to configure graceful startup for Spring Cloud application to perform operations such as upgrade, restart, and scale-out during component O&M.

Procedure

  1. Enable spring-boot-starter-actuator for Spring Cloud.

    1. Add the spring-boot-starter-actuator dependency to the pom.xml file of the source code corresponding to the component. (Version 2.3.0 or later is recommended.)
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</artifactId>
          <version>{Your Spring boot version}</version>
      </dependency>
    2. Add the following configurations to the application.properties file:
      Table 1 application.properties

      Spring Boot Version

      Configuration

      2.3.0/2.3.1

      management.health.probes.enabled=true

      >= 2.3.2

      management.endpoint.health.probes.enabled=true

      management.health.livenessState.enabled=true

      management.health.readinessState.enabled=true

    3. Update code.
      • If your component is deployed using source code, update the modified source code to the source code repository.
      • If your component is deployed using a software package, pack the new code into a software package and upload the new package to the software package repository.
    4. Use the new source code or software package to upgrade the component.

  2. Configure component health check.

    1. Log in to CAE. Choose Component Configurations.
    2. Select the target component from the drop-down list in the upper part of the page.
    3. Configure readiness probe by referring to Configuring Health Check. The parameters are as follows:
      Table 2 Readiness probe parameters

      Parameter

      Description

      Check Method

      Select HTTP.

      Port

      Enter the listening port of your component.

      Path

      • For Spring Boot 2.3 and later, enter /actuator/health/readiness.
      • For Spring Boot versions earlier than 2.3, enter /actuator/health.

      Protocol

      Select the protocol of your component.

      Check Interval

      Enter 10.

      Latency

      Enter 0.

      Timeout Interval

      Enter 1.

      Success Threshold

      Enter 1.

      Failure Threshold

      Enter 3.

    4. Upgrade the component. For details, see Upgrading a Component.

  3. Verify the configuration.

    1. Choose Components. If the status of the target component is Running, go to the next step. Otherwise, the configuration fails.
    2. Choose Component Events and select the target component from the drop-down list in the upper part of the page. If the Component instance healthy event exists, the configuration is successful. Otherwise, the configuration fails.