spring-cloud-starter-bus-kafka利用kafka消息总线实现动态刷新配置

利用上一节的config-client,修改依赖为spring-cloud-starter-bus-kafka:

		
			org.springframework.cloud
			spring-cloud-starter-bus-kafka
		

假设kafka,zookeeper,都是运行在本地,都是默认端口,那么不需要增加额外的配置,即可完全模仿上一节的例子:

spring-cloud-starter-bus-kafka利用kafka消息总线实现动态刷新配置_第1张图片

比如发送刷新配置请求:curl http://127.0.0.1:7002/actuator/bus-refresh/ -d '' -H 'content-type:application/json'

观察到日志:

2019-04-14 20:35:38.067  INFO 73543 --- [container-0-C-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []

同时,kafka服务端控制台可见:

RdeMacBook-Pro:kafka r$ ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic springCloudBus --from-beginning
{"type":"RefreshRemoteApplicationEvent","timestamp":1555245081633,"originService":"config-client:7002:108286c6ad0ece8b6a1a52a1990658b2","destinationService":"**","id":"862c45f1-15b9-4eaa-82d0-a54ee8f4f958"}
{"type":"AckRemoteApplicationEvent","timestamp":1555245081732,"originService":"config-client:7002:108286c6ad0ece8b6a1a52a1990658b2","destinationService":"**","id":"5b91765b-9987-4bd5-88b6-9d4fee98a28a","ackId":"862c45f1-15b9-4eaa-82d0-a54ee8f4f958","ackDestinationService":"**","event":"org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent"}
{"type":"AckRemoteApplicationEvent","timestamp":1555245090613,"originService":"config-client:7003:4e14a1a6ed5fa4f2e8a392ae0373d6d3","destinationService":"**","id":"5f65b526-93d9-4f36-a927-967cc4eff5e3","ackId":"862c45f1-15b9-4eaa-82d0-a54ee8f4f958","ackDestinationService":"**","event":"org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent"}

 

你可能感兴趣的:(Spring-boot,spring-cloud,kafka,java)