Java spring cloud b2b2b2c o2o multi user shopping mall springcloud Architecture - refresh configuration with spring cloud Bus

We use the spring cloud distributed micro service Cloud Architecture to build b2b2c e-commerce system. In addition to the system services provided by the architecture itself, we split the business services of b2b2c into different business micro services.

As our business system becomes larger and more complex, various configurations will increase. Once the configuration file is modified, the service will be stopped and then restarted for the commonservice config configuration center to make the configuration effective.

If there are few services, we can start it manually, but it will certainly have a certain impact on the stability of the business and system.

If hundreds of services are manually operated, I think the operation and maintenance personnel or technical personnel will go mad.

To solve the above problems, the commonservice config server and the business microservice are respectively configured. The server is responsible for configuring the configuration files stored in git (svn or local file system) (we use the local configuration scheme to directly update the configuration files to linux),

The business micro service obtains the relevant configuration from the server configuration center through configuration. If the configuration file changes, the latest configuration information will be obtained by refreshing the business micro service.

spring cloud Bus connects nodes of the distributed system through a lightweight message broker. This can be used to broadcast state changes, such as configuration changes, or other management instructions.

Next, we will implement the spring cloud Bus scheme to dynamically refresh the server configuration. The specific steps are as follows:

  1. For commonservice config service configuration, please refer to the previous link:

  2. Business microservice configuration (take the Hong member servcie member service as an example):

<span style="font-size: 16px;">        <dependency>  
            <artifactId><span style="font-size: 16px;">spring-boot-starter-actuator</span></artifactId>  
             <artifactId><span style="font-size: 16px;">spring-cloud-starter-bus-amqp</span></artifactId>  

yml file configuration:

<span style="font-size: 16px;">server:  
  port: 5012  
    name: honghu-member-client  
    active: dev,discoveryClient  
        enabled: true  
        service-id: commonservice-config-server  
      <span style="font-size: 16px;"><strong>name: honghu-member  
      profile: dev  
        enabled: true  #Enable message tracking < / strong >          
    port: 5672  
    username: honghu  
    password: honghu</strong>  </span>   
      defaultZone: http://honghu:123456@localhost:8761/eureka/  
    prefer-ip-address: true  
    root: INFO INFO  
    enabled: false  
    enabled: false</span>  

Write a test class ( to get configuration items

<span style="font-size: 16px;">package;  
import org.springframework.beans.factory.annotation.Value;  
import org.springframework.web.bind.annotation.GetMapping;  
import org.springframework.web.bind.annotation.RestController;  
public class MemberController {  
    private String profile;  
    public String getProfile() {  
        return this.profile;  
  1. Check whether the registration center, commonservice config and Honghu member service services have been registered successfully
  2. Access the profile to obtain the configuration information corresponding to the profile (original configuration):

Visit http://localhost:7071/profile = =, visit result: 123456

  1. Modify the configuration file in the config configuration center, and change the profile=123456 to honghu123456

Visit http://localhost:7071/profile = =, visit result: 123456

  1. Using spring cloud bus refresh scheme (testing with post man test tool)


Visit http://localhost:7071/profile = =, visit result: honghu123456

So far, the dynamic refresh scheme of the whole commonservice config configuration center has been sorted out

Welcome to join me in learning about spring cloud to build a microservice Cloud Architecture. I will record the process and essence of the recently developed spring cloud microservice Cloud Architecture, and help more friends who are interested in developing the spring cloud framework. Let's discuss the process of building the spring cloud architecture and how to apply it to enterprise projects.

Spring Cloud: B2B2C e-commerce platform built by distributed micro service cloud of large enterprises

Reprinted at:

75 original articles published, 63 praised, 2983 visited
Private letter follow

Tags: Spring git svn Linux

Posted on Sun, 09 Feb 2020 23:41:48 -0500 by markmusicman