【问题标题】:Rest Client - Can i set connectionPoolSize?Rest Client - 我可以设置 connectionPoolSize 吗?
【发布时间】:2020-12-16 22:54:33
【问题描述】:
Microprofile 允许像这样从 RestClient 定义 connectionPoolSize:
io.smallrye.restclient.tests.proxy.HelloClient/property/resteasy.connectionPoolSize = 4
当我在我的项目中设置此属性时,quarkus 会忽略它。如何定义?
【问题讨论】:
标签:
resteasy
quarkus
microprofile
quarkus-rest-client
【解决方案1】:
- 创建类 MyRestClientBuilderListener 实现 RestClientBuilderListener:
package org.myproject.config
public class MyRestClientBuilderListener implements RestClientBuilderListener {
static final Logger LOG = LoggerFactory.getLogger(MgiRestClientBuilderListener.class);
static final String CONNECTION_POOL_SIZE_PROP = "config.restclient.connectionPoolSize";
@Override
public void onNewBuilder(RestClientBuilder builder) {
Config cfg = ConfigProvider.getConfig();
Integer poolSizeConnection = cfg.getValue(CONNECTION_POOL_SIZE_PROP, Integer.class);
if(poolSizeConnection == null) {
poolSizeConnection = 50;//default
}
builder.property("resteasy.connectionPoolSize", poolSizeConnection);
}
}
- 在 META-INF\services 中创建名称为 org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener 的文件,内容为:
org.myproject.config.MyRestClientBuilderListener
【解决方案2】:
如果您配置的客户端是@RegisterRestClient(configKey="myClient"),设置池大小使用:
quarkus.rest-client.myClient.connection-pool-size: 5
(...而不是 myClient/mp-rest/connectionPoolSize)