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 use Spring Cloud Bus to notify changes to the configuration file of the micro-service architecture

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article focuses on "how to use Spring Cloud Bus to notify changes to the configuration file of the micro-service architecture", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use Spring Cloud Bus to notify changes to the configuration file of the microservice architecture."

Spring Cloud Bus connects distributed nodes with lightweight message agents. It can be used for broadcast profile changes or communication between services, as well as 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 just need to configure spring-cloud-starter-bus-amqp in the configuration file; that means we need to install rabbitMq and click rabbitmq to download. As for how to use rabbitmq, 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-bus-amqp

Add the configuration of RabbitMq to the configuration file application.properties, including the address, port, user name and password of RabbitMq. The code is as follows:

Spring.rabbitmq.host=localhostspring.rabbitmq.port=5672# spring.rabbitmq.username=# spring.rabbitmq.password=

If rabbitmq has a user name and password, just enter it.

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 in order to update the configuration file. At this point, we just need to send a post request: http://localhost:8881/bus/refresh, and you will find that config-client will reproduce the belly button 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 / bus/refresh interface can specify services, even with the "destination" parameter, such as "/ bus/refresh?destination=customers:**", which refreshes all services named customers, regardless of ip.

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.

At this point, I believe you have a deeper understanding of "how to use Spring Cloud Bus to notify the changes to the configuration file of the micro-service architecture". You might as well do it in practice. 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

Internet Technology

Wechat

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

12
Report