我正在使用spring-cloud-bus,配置服务器,配置客户端和Rabbitmq(使用docker映像)。在我的设置中,有2个配置客户端和2个配置服务器。
当配置客户端,配置服务器和Rabbitmq都在一台计算机(Linux或Windows)上运行时,spring-cloud-bus运行良好,即当我请求任何配置客户端的/ bus / refresh时,所有配置客户端正在使用最新配置进行更新。
但是如果config-clients,config-servers和rabbitmq都没有在一台计算机上运行(我在linux1上运行config-server1,config-client1,rabbitmq,在linux2上运行config-server2,config-client2),则春季-云总线无法正常工作,即当我请求任何配置客户端的/ bus / refresh时,有时所有配置客户端都会更新其配置,有时只有一个配置客户端会更新其配置。
我尝试了很多次,但我不明白为什么spring-cloud-bus会发生这种现象。谁能帮助我了解这一点?
这是我的配置服务器的pom:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
这是我的配置服务器的applications.properties:
spring.application.name=config-server
server.port=9999
eureka.client.serviceUrl.defaultZone=http://server1:9761/eureka/,http://server2:9762/eureka/
spring.cloud.config.server.git.uri=git@gitmylab.365ime.com:liuxiang/springcloud-config-server.git
security.user.name=liuxiang
security.user.password=123456
spring.cloud.config.server.git.searchPaths=myconfig
spring.cloud.config.label=master
spring.cloud.config.server.git.basedir=/data/${spring.application.name}
encrypt.key=key1
这是我的配置客户端的pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!--引入此依赖才能调用refresh接口,更新配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--消息总线-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
这是我的配置客户端的bootstrap.properties:
spring.cloud.config.name=config
spring.profiles.active=dev
spring.cloud.config.label=master
eureka.client.serviceUrl.defaultZone=http://server1:9761/eureka/,http://server2:9762/eureka/
spring.application.name=config-client
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=config-server
management.security.enabled=false
server.port=8881
spring.cloud.config.server.git.basedir=/data/${spring.application.name}
spring.cloud.config.username=liuxiang
spring.cloud.config.password=123456
spring.rabbitmq.host=192.168.50.69
spring.rabbitmq.port=5672
感谢您的帮助〜