In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Spring Cloud Bus connects distributed nodes with lightweight message agents. It can be used to broadcast changes to configuration files or to communicate between services
It can also be used for monitoring. This article is about the use of Spring Cloud Bus to notify changes to the configuration file of the microservice architecture.
I. preparatory work
This paper is based on the previous article. According to the official documentation, we only need to configure spring-cloud-starter-bus-amqp in the configuration file
To understand the springcloud architecture, please add: 3536247259, which means we need to install rabbitMq and click rabbitmq to download it. As for how
Use rabbitmq, under the search engine.
Second, transform config-client
Add the startup dependency spring-cloud-starter-bus-amqp to the pom file, and the complete configuration file is as follows:
Org.springframework.cloud spring-cloud-starter-config org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud- Starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-bus-amqp org.springframework.boot spring-boot-starter-actuator
Add the configuration of RabbitMq to the configuration file application.properties, including the address, port, user name and password of RabbitMq. And you need to add three configurations of spring.cloud.bus, as follows:
Spring.rabbitmq.host=localhostspring.rabbitmq.port=5672spring.rabbitmq.username=guestspring.rabbitmq.password=guestspring.cloud.bus.enabled=truespring.cloud.bus.trace.enabled=truemanagement.endpoints.web.exposure.include=bus-refresh
The ConfigClientApplication startup class code is as follows:
@ SpringBootApplication@EnableEurekaClient@EnableDiscoveryClient@RestController@RefreshScopepublic class ConfigClientApplication {/ * http://localhost:8881/actuator/bus-refresh * / public static void main (String [] args) {SpringApplication.run (ConfigClientApplication.class, args);} @ Value ("${foo}") String foo @ RequestMapping (value = "/ hi") public String hi () {return foo;}}
Start eureka-server, then confg-cserver, and then start the two config-client, ports 8881 and 8882.
Visit the http://localhost:8881/hi or http://localhost:8882/hi browser to display:
Foo version 3
At this point, we go to the code repository to change the value of foo to "foo version 4", that is, to change the value of the configuration file foo. If it is a traditional practice, you need to restart the service.
To achieve the update of the profile. At this point, we just need to send the post request: http://localhost:8881/actuator/bus-refresh, you will find
Config-client will reread the configuration file
Reread the configuration file:
At this point, we visit the http://localhost:8881/hi or http://localhost:8882/hi browser to show:
Foo version 4
In addition, the / actuator/bus-refresh interface can specify services, even with the "destination" parameter, such as "/ actuator/bus-refresh?destination=customers:**", which refreshes all services with the service name customers.
III. Analysis
The architecture diagram at this time:
When the git file is changed, the request / bus/refresh/; is sent to the config-client with port 8882 using post through the pc side. At this time, port 8882 will send a message to other services through the message bus, so that the entire micro-service cluster reaches the update profile.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.