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

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

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-kafka</artifactId>
		</dependency>

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

比如发送刷新配置请求: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"}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值