上节配置了spring cloud config server,集中管理配置文件,当配置文件发生变化时,客户端通过
curl -X POST http://客户端地址:端口/actuator/refresh 可以刷新客户端配置,但是如果微服务多了,一个微服务有多个实例在运行,需要一个个去刷新,采用bus消息总线,可以实现一键刷新所有实例的配置。
原理图:
一、启动kafka (安装参看我的其他文章)
cd kafka_2.12-2.1.0
启动自带的zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties &
启动kafka
bin/kafka-server-start.sh config/server.properties &
查看topic
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
二、spring cloud config server 配置
1. pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.linbsoft</groupId>
<artifactId>microservice-config-server-8401</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>microservice-config-server-8401</name>
<description>Demo project for Spring Boot microservice-microservice-config-server-8401</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.M3</spring-cloud.version><!-- Finchley.M8 -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<