一次为所有客户端定义 /mp-rest/url Quarkus YAML
Define /mp-rest/url for all clients at once Quarkus YAML
在 Quarkus 中,我可以通过 /mp-rest/url 属性 在我的 YAML 文件中为我的客户定义基础 url。目前我的 YAML 文件如下所示:
...
"%dev":
some:
package:
name:
client:
ExampleService1/mp-rest/url: https://some.url.com
ExampleService2/mp-rest/url: https://some.url.com
"%tst":
some:
package:
name:
client:
ExampleService1/mp-rest/url: https://some.other.url.com
ExampleService2/mp-rest/url: https://some.other.url.com
...
如您所见,我有多个服务,它们在各自的开发环境中都具有相同的基础 url(所有开发基础 url 相同,所有 tst 基础 url是一样的)。
因为我对每个环境的服务都有相同的基础 url,所以我不想为我拥有的每个服务都定义 url。
我的问题:
有没有办法一次为我的客户端文件夹中的所有服务定义 /mp-rest/url?
它必须看起来像这样(显然这不起作用):
"%dev":
some:
package:
name:
client:
*/mp-rest/url: https://some.url.com
"%tst":
some:
package:
name:
client:
*/mp-rest/url: https://some.other.url.com
您可以定义可在所有 REST 客户端中使用的单一配置。
首先,使用自定义名称而不是默认包 + class 名称定义配置:
country-api/mp-rest/url=https://restcountries.eu/rest
然后告诉 REST 客户端使用此自定义配置而不是默认配置:
@RegisterRestClient(configKey="country-api")
public interface CountriesService {
[...]
}
您可以在此处找到更多信息:
https://quarkus.io/guides/rest-client#create-the-configuration
编辑:对于 application.yml 这样的东西应该有效
country-api/mp-rest/url: https://restcountries.eu/rest
在 Quarkus 中,我可以通过 /mp-rest/url 属性 在我的 YAML 文件中为我的客户定义基础 url。目前我的 YAML 文件如下所示:
...
"%dev":
some:
package:
name:
client:
ExampleService1/mp-rest/url: https://some.url.com
ExampleService2/mp-rest/url: https://some.url.com
"%tst":
some:
package:
name:
client:
ExampleService1/mp-rest/url: https://some.other.url.com
ExampleService2/mp-rest/url: https://some.other.url.com
...
如您所见,我有多个服务,它们在各自的开发环境中都具有相同的基础 url(所有开发基础 url 相同,所有 tst 基础 url是一样的)。
因为我对每个环境的服务都有相同的基础 url,所以我不想为我拥有的每个服务都定义 url。
我的问题: 有没有办法一次为我的客户端文件夹中的所有服务定义 /mp-rest/url? 它必须看起来像这样(显然这不起作用):
"%dev":
some:
package:
name:
client:
*/mp-rest/url: https://some.url.com
"%tst":
some:
package:
name:
client:
*/mp-rest/url: https://some.other.url.com
您可以定义可在所有 REST 客户端中使用的单一配置。
首先,使用自定义名称而不是默认包 + class 名称定义配置:
country-api/mp-rest/url=https://restcountries.eu/rest
然后告诉 REST 客户端使用此自定义配置而不是默认配置:
@RegisterRestClient(configKey="country-api")
public interface CountriesService {
[...]
}
您可以在此处找到更多信息: https://quarkus.io/guides/rest-client#create-the-configuration
编辑:对于 application.yml 这样的东西应该有效
country-api/mp-rest/url: https://restcountries.eu/rest