如何使用 https 将 spring-config-server 与 vertx 一起使用?
How to use spring-config-server with vertx using https?
我有一个 vert.x 应用程序,它使用 spring-config-server 来获取值。当配置服务器在 http 上时,代码完全可以正常工作,但是当 spring-config-server 移动到 https 时,代码不起作用。
Vertx vertx = Vertx.vertx();
List<ConfigStoreOptions> configStores = new ArrayList<>();
List<String> configUrls = CoreConfigBean.getUrls(environment);
configUrls.forEach(url -> {
configStores.add(new ConfigStoreOptions().setType("spring-config-server")
.setConfig(new JsonObject().put("url", url).put("timeout",
Long.parseLong(ConfigurationUtil.CONFIG_SERVER_TIME_OUT))));
});
ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions();
configStores.forEach(configRetrieverOptions::addStore);
ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions.setScanPeriod(0));
CompletableFuture<JsonObject> configLoader = new CompletableFuture<JsonObject>();
retriever.getConfig(json -> {
if (json.succeeded()) {
JsonObject jsonObject = json.result();
if (jsonObject != null) {
jsonObject.iterator().forEachRemaining(sourceValue -> System.setProperty(sourceValue.getKey(),
sourceValue.getValue().toString()));
}
configLoader.complete(json.result());
json.mapEmpty();
retriever.close();
vertx.close();
} else {
json.otherwiseEmpty();
retriever.close();
vertx.close();
}
});
configLoader.get();
尝试通过在配置中提供 httpClientConfiguration
元素来指定 HttpClientOptions
:
...
.setConfig(new JsonObject()
.put("url", url)
.put("timeout", Long.parseLong(ConfigurationUtil.CONFIG_SERVER_TIME_OUT))
.put("httpClientConfiguration", new JsonObject()
.put("trustAll", true)
.put("ssl", true)));
...
我有一个 vert.x 应用程序,它使用 spring-config-server 来获取值。当配置服务器在 http 上时,代码完全可以正常工作,但是当 spring-config-server 移动到 https 时,代码不起作用。
Vertx vertx = Vertx.vertx();
List<ConfigStoreOptions> configStores = new ArrayList<>();
List<String> configUrls = CoreConfigBean.getUrls(environment);
configUrls.forEach(url -> {
configStores.add(new ConfigStoreOptions().setType("spring-config-server")
.setConfig(new JsonObject().put("url", url).put("timeout",
Long.parseLong(ConfigurationUtil.CONFIG_SERVER_TIME_OUT))));
});
ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions();
configStores.forEach(configRetrieverOptions::addStore);
ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions.setScanPeriod(0));
CompletableFuture<JsonObject> configLoader = new CompletableFuture<JsonObject>();
retriever.getConfig(json -> {
if (json.succeeded()) {
JsonObject jsonObject = json.result();
if (jsonObject != null) {
jsonObject.iterator().forEachRemaining(sourceValue -> System.setProperty(sourceValue.getKey(),
sourceValue.getValue().toString()));
}
configLoader.complete(json.result());
json.mapEmpty();
retriever.close();
vertx.close();
} else {
json.otherwiseEmpty();
retriever.close();
vertx.close();
}
});
configLoader.get();
尝试通过在配置中提供 httpClientConfiguration
元素来指定 HttpClientOptions
:
...
.setConfig(new JsonObject()
.put("url", url)
.put("timeout", Long.parseLong(ConfigurationUtil.CONFIG_SERVER_TIME_OUT))
.put("httpClientConfiguration", new JsonObject()
.put("trustAll", true)
.put("ssl", true)));
...