Introduction
We Spring Cloud tutorial series six: Distributed Configuration Center Spring Cloud Config (F version) mentioned in the client wants to get the latest configuration requires access / actuator / refresh, although we can simplify this process by webhook, but when customers more and more end time, this solution is not very suitable, we can use Spring Cloud Bus to solve this problem
github address: https: //github.com/erlieStar/spring-cloud-learning
Realization of multi-client configuration updates
复制consumer-config-cluster(spring-cloud-config )为consumer-config-cluster-bus(spring-cloud-bus)
1. The following items arranged
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<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>
bootstrap.yaml
server:
port: 6001
spring:
application:
name: javashitang # 要获取的配置的应用名
cloud:
config:
profile: dev
label: master
discovery:
enabled: true
service-id: config-cluster
bus:
enabled: true
trace:
enabled: true
rabbitmq:
host: myhost
port: 5672
username: guest
password: guest
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
management:
endpoints:
web:
exposure:
include: bus-refresh
2. Start classes are as follows
@RefreshScope
@RestController
@EnableEurekaClient
@SpringBootApplication
public class ConsumerConfigClusterBus {
public static void main(String[] args) {
SpringApplication.run(ConsumerConfigClusterBus.class);
}
@Value("${from}")
private String from;
@RequestMapping("from")
public String from() {
return this.from;
}
}
rabbitmq installation and knowledge read my blog, is no longer introduced
Start-Service-sequentially Eureka (Eureka-Spring-Cloud)
config-Cluster (Spring-Cloud-config)
start two consumer-config-cluster-bus ( spring-cloud-bus)
Method to start two instances of the idea, referring to Spring Cloud Tutorial Series II: The client load balancing Spring Cloud Ribbon (F version)
Access
HTTP: // localhost: 6001 / from
HTTP: // localhost: 6002 / from
returns as follows
javashitang-git-dev-update
The javashitang-dev.yaml would read as follows, and submitted to github
from: javashitang-git-dev
Use postman calls with post http way: // localhost: 6001 / actuator / bus-refresh /
再次访问
http://localhost:6001/from
http://localhost:6002/from
At this point it is returned
javashitang-git-dev
Proved more successful client configuration and refresh
Welcome attention
Reference blog
[1]https://windmt.com/2018/04/19/spring-cloud-9-config-eureka-bus/