基于 Solon Cloud Config 动态更新路由配置
如果网关配置没有使用自动发现机制(路由是手动配置的)。
如果配置放在 water, consul, nacos, zookeeper, polaris 等,修改后想同步路由配置。可使用 solon cloud config 的 CloudConfigHandler 组件,时实订阅最新的配置。
@CloudConfig("demo.yml")
public class DemoUpdate implements CloudConfigHandler {
@Inject
CloudRouteRegister routeRegister;
@Override
public void handle(Config config) {
GatewayProperties gatewayProperties = new Props(config.toProps())
.getProp(GatewayProperties.SOLON_CLOUD_GATEWAY)
.toBean(GatewayProperties.class);
routeRegister.route(gatewayProperties);
}
}
solon cloud config 的更多内容,参考: 《使用分布式配置服务》