【问题标题】:Deploy Quarkus Microservice with RestClient使用 RestClient 部署 Quarkus 微服务
【发布时间】:2021-09-01 14:31:32
【问题描述】:

任何人都知道如何在 Quarkus 中替换 application.yaml 中的字符“/”

# REST Client configuration property
org:
  acme:
    restclient:
      CountriesService/mp-rest/url: https://restcountries.eu/rest

当我部署时,似乎出现了这个错误

Error: release insurance-svc failed, and has been uninstalled due to atomic being set: ConfigMap "insurance-svc-dev-config" is invalid: [data[coreClient/mp-rest/url]: Invalid value: "coreClient/mp-rest/url": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name', or 'KEY_NAME', or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+'), data[identityClient/mp-rest/scope]: Invalid value: "identityClient/mp-rest/scope": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name', or 'KEY_NAME', or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+'), data[coreClient/mp-rest/scope]: Invalid value: "coreClient/mp-rest/scope": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name', or 'KEY_NAME', or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+'), data[identityClient/mp-rest/url]: Invalid value: "identityClient/mp-rest/url": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name', or 'KEY_NAME', or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+')

有没有办法改变它的配置方式而不将整个 baseUri 添加到注释 @RegisterRestClient() 中?

【问题讨论】:

标签: java deployment quarkus rest-client


【解决方案1】:

您可以使用不同的方法,您可以创建自定义配置属性来保存 URI。然后创建一个读取或注入此配置属性并用于实例化您的 REST 客户端的工厂。

URL apiUrl = new URL("http://localhost:9080/onlineMusicService");
MusicPlaylistService playlistSvc =
    RestClientBuilder.newBuilder()
                     .baseUrl(apiUrl)
                     .register(PlaylistResponseExceptionMapper.class)
                     .build(MusicPlaylistService.class);

List<String> playlistNames = playlistSvc.getPlaylistNames();
for (String name : playlistNames) {
    List<Song> songs = playlistSvc.getPlaylist(name);
    if (hasSongBy(songs, "band name")) {
        coolPlaylists.add(name);
    }
}

您可以使用您想要的名称从自定义配置属性中读取该 url。

【讨论】:

    【解决方案2】:

    我建议观看此拉取请求:https://github.com/quarkusio/quarkus/pull/17220 一旦合并并发布了 Quarkus 版本,您就可以改用 quarkus.rest-client."org.acme.restclient.CountriesService".url=https://restcountries.eu/rest - 密钥不包含斜线,因此它与 Kubernetes 兼容

    【讨论】:

      猜你喜欢
      • 2018-06-14
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 2020-07-03
      • 1970-01-01
      相关资源
      最近更新 更多