The simplest SpringCloud Tutorial in History | Chapter 8: Spring Cloud BUS

For the latest Finchley version, please visit:
https:// www.fangzhipeng.com/springcloud/2018/08/30/sc-f8-bus/
or
http://blog.csdn.net/forezp/article/details/81041062

Spring Cloud Bus connects distributed nodes with a lightweight message broker. It can be used to broadcast configuration file changes or communication between services, and can also be used for monitoring. This article is about using Spring Cloud Bus to implement notification of changes to the configuration file of the microservice architecture.

This article is still based on the previous article Article to achieve. According to the official documentation, we only need to configure spring-cloud-starter-bus-amqp in the configuration file; this means we need to install rabbitMq, click rabbitmq to download. As for how to use rabbitmq, go to the search engine.

Add start in the pom file Relying on spring-cloud-starter-bus-amqp, the complete configuration file is as follows:


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


if rabbitmq has User name and password, just enter it.

start eureka-server, confg-cserver, start two config-clients, the ports are: 8881, 8882.

Visit http://localhost :8881/hi or http://localhost:8882/hi browser display:

foo version 3

< span style="color: #000000; text-decoration: underline">At this time, we go to the code repository and change the value of foo to “foo version 4”, that is, change the value of the configuration file foo. If it is the traditional method, the service needs to be restarted to achieve the update of the configuration file. At this point, we only need to send a post request: http://localhost:8881/bus/refresh, you will find that config-client will re-read the configuration file

< span style="text-decoration: underline">Paste_Image.png Re-read the configuration file:

Paste_Image.pngAt this time, we visit http://localhost:8881/hi or http://localhost:8882/hi and the browser displays:

foo version 4

In addition, the /bus/refresh interface can specify services, that is, use “destination” Parameter, How much is IELTS training generally such as “/bus/refresh?destination=customers:**” which means refreshing all services named customers Service, regardless of ip.

The architecture diagram at this time:
Paste_Image.pngWhen the git file is changed, post a request /bus/refresh/ to the config-client port 8882 through the PC terminal; at this time, port 8882 will send a message. The message bus is passed to other services, so that the entire microservice cluster can update the configuration file.

can be used as a custom Message Broker, just spring-cloud-starter-bus-amqp, and then write the configuration in the configuration file, ibid.

Tracing Bus Events:
need to set: spring.cloud.bus.trace.enabled=true, if you do that, then Spring Boot TraceRepository (if it exists) will display all events and all acks sent by each service instance, For example: (from the official website)


Download the source code of this article:
https://github.com/forezp/SpringCloudLearning/tree/master/chapter8

For the latest Finchley version, please visit:
https://www.fangzhipeng.com/ springcloud/2018/08/30/sc-f8-bus/
or< /span>
http://blog.csdn.net/forezp/article/details /81041062

Spring Cloud Bus will The distributed nodes are connected by a lightweight message broker. It can be used to broadcast configuration file changes or communication between services, and can also be used for monitoring. This article is about using Spring Cloud Bus to implement notification of changes to the configuration file of the microservice architecture.

This article is still based on the previous article Article to achieve. According to the official documentation, we only need to configure spring-cloud-starter-bus-amqp in the configuration file; this means we need to install rabbitMq, click rabbitmq to download. As for how to use rabbitmq, go to the search engine.

Add start in the pom file Relying on spring-cloud-starter-bus-amqp, the complete configuration file is as follows:


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


if rabbitmq has User name and password, just enter it.

start eureka-server, confg-cserver, start two config-clients, the ports are: 8881, 8882.

Visit http://localhost :8881/hi or http://localhost:8882/hi browser display:

foo version 3

< span style="color: #000000; text-decoration: underline">At this time, we go to the code repository and change the value of foo to “foo version 4”, that is, change the value of the configuration file foo. If it is the traditional method, the service needs to be restarted to achieve the update of the configuration file. At this point, we only need to send a post request: http://localhost:8881/bus/refresh, you will find that config-client will re-read the configuration file

< span style="text-decoration: underline">Paste_Image.png Re-read the configuration file:

Paste_Image.pngAt this time, we visit http://localhost:8881/hi or http://localhost:8882/hi and the browser displays:

foo version 4

In addition, the /bus/refresh interface can specify services, that is, use “destination” Parameter, How much is IELTS training generally such as “/bus/refresh?destination=customers:**” which means refreshing all services named customers Service, regardless of ip.

The architecture diagram at this time:
Paste_Image.pngWhen the git file is changed, post a request /bus/refresh/ to the config-client port 8882 through the PC terminal; at this time, port 8882 will send a message. The message bus is passed to other services, so that the entire microservice cluster can update the configuration file.

can be used as a custom Message Broker, just spring-cloud-starter-bus-amqp, and then write the configuration in the configuration file, ibid.

Tracing Bus Events:
need to set: spring.cloud.bus.trace.enabled=true, if you do that, then Spring Boot TraceRepository (if it exists) will display all events and all acks sent by each service instance, such as: (From the official website)


Download the source code of this article:
< span style="color: #000000; text-decoration: underline">https://github.com/forezp/SpringCloudLearning/tree/master/chapter8

< /p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1265 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.