Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize automatic refresh function of spring cloud config and bus components

Shulou Source: shulou.com Published: 2022-06-02 20:14:16 11月13日 Update

This article focuses on "spring cloud config and bus components how to achieve automatic refresh function", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "spring cloud config and bus components how to achieve automatic refresh function" bar!

1. Start RabbitMQ

two。 Modify config server dependency: (the boot and cloud versions should not be too high, otherwise the request to refresh the configuration cannot be used)

Org.springframework.cloud spring-cloud-starter-consul-discovery org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-config-server org.springframework.cloud spring-cloud-starter-bus-amqp org.springframework.boot spring-boot-starter-web

Configuration:

Spring: cloud: consul: host: localhost port: 8500 config: server: git: uri: https://gitee.com/xiang_pei/config.git default-label: master application: name: CONFIGSERVER rabbitmq: host: localhost port: 5672 username: guest password: guest virtual-host: / # expose all endpoints Easy to send update configuration request management: endpoints: web: exposure: include: "*"

Startup: (startup class plus @ EnableConfigServer) mq will have a temporary queue

3. Modify the microservice (that is, the client) dependency:

Org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-consul-discovery org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-starter-config org.springframework.cloud spring-cloud-starter-bootstrap org. Springframework.cloud spring-cloud-starter-bus-amqp

Configuration: unchanged (the configuration of rabbitmq should be written to gitee) bootstrap.properties

Spring.cloud.consul.host=localhostspring.cloud.consul.port=8500spring.application.name=CONFIGCLIENTspring.cloud.config.discovery.service-id=CONFIGSERVERspring.cloud.config.discovery.enabled=truespring.cloud.config.name=configspring.cloud.config.label=masterspring.cloud.config.profile=dev

Run:

Wrote a test method.

The name property is the name of the profile on gitee

No problem

4. Using webhooks to realize automatic refresh configuration

Send a post request to the config server

Http://localhost:8080/actuator/bus-refresh

The specific path is based on the project

In the config Management of gitee, click webhooks

Url will fill in the above one, because you need a public network to test, so I won't demonstrate it for the time being.

After setting up, changing the configuration of gitee will refresh automatically.

At this point, I believe you have a deeper understanding of "spring cloud config and bus components how to achieve automatic refresh function", might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Configuration functions components services content methods learning testing practicality deeper interest practicality practical customer client properties simple operation files more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Shulou Information MariaDB Shulou Tech Info