Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report