利用上一节的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"}

 

Logo

Kafka开源项目指南提供详尽教程,助开发者掌握其架构、配置和使用,实现高效数据流管理和实时处理。它高性能、可扩展,适合日志收集和实时数据处理,通过持久化保障数据安全,是企业大数据生态系统的核心。

更多推荐