复制步骤:
我们使用micronaut应用程序作为aws ecs中的docker容器,并使用代理从vpc中进行公共访问。代理具有动态ip分配,ip可以随时间变化。
在这个应用程序中,自定义httpclientconfiguration用于rxhttpclient。代理按以下方式设置
配置类:
public class CustomHttpClientConfiguration extends HttpClientConfiguration {
private final DefaultHttpClientConfiguration.DefaultConnectionPoolConfiguration
connectionPoolConfiguration;
@Inject
public CustomHttpClientConfiguration(ApplicationConfiguration applicationConfiguration,
DefaultHttpClientConfiguration.DefaultConnectionPoolConfiguration
connectionPoolConfiguration) {
super(applicationConfiguration);
this.connectionPoolConfiguration = connectionPoolConfiguration;
setProxyType(Proxy.Type.HTTP);
InetSocketAddress inetSocketAddress = new InetSocketAddress("proxyHostName", 3128);
setProxyAddress(inetSocketAddress);
setConnectTtl(Duration.ofSeconds(60));
}
}
客户端类的片段如下:@singleton public class customdetailshttpclientimpl{
private RxHttpClient httpClient;
public CustomDetailsHTTPClientImpl(@client(value = "${host}", configuration =
CustomHttpClientConfiguration.class) RxHttpClient httpClient) {
this.httpClient = httpClient;
}
public getPropertyValue(){
Flowable<HttpResponse<String>> flowableHttpResponse =
httpClient.exchange(HttpRequest.GET("URI"), String.class);
HttpResponse<String> httpResponse;
httpResponse = flowableHttpResponse.blockingSingle();
}
}
预期行为:因为代理是动态的。httpclient应该识别ip地址更改并转发请求。
实际行为:httpclientconfiguration类在启动时获取ip(使用inetsocketaddress设置)。然后缓存这个ip地址。当代理ip地址更改时,它抛出异常。当我们重新启动应用程序时,新的ip地址被获得并且工作正常。
stacktrace:原因:io.micronaut.http.client.exceptions.httpclientexception:连接错误:连接被拒绝:proxyhost/xx.xx.xx.xx:3128at io.micronaut.http.client.defaulthttpclient.lambda$null$26(defaulthttpclient)。java:1038)在io.netty.util.concurrent.defaultpromise.notifylistener0(defaultpromise。java:500)在io.netty.util.concurrent.defaultpromise.notifylisteners0(默认承诺。java:493)在io.netty.util.concurrent.defaultpromise.notifylistenersnow(defaultpromise。java:472)在io.netty.util.concurrent.defaultpromise.notifylisteners(defaultpromise。java:413)在io.netty.util.concurrent.defaultpromise.setvalue0(defaultpromise。java:538)在io.netty.util.concurrent.defaultpromise.setfailure0(defaultpromise。java:531)在io.netty.util.concurrent.defaultpromise.tryfailure(defaultpromise。java:111)在io.netty.channel.nio.abstractniochannel$abstractniosafsafe.fulfillconnectpromise(abstractniochannel.com)。java:323)在io.netty.channel.nio.abstractniochannel$abstractniosafsafe.finishconnect(abstractniochannel。java:339)在io.netty.channel.nio.nioeventloop.processselectedkey(nioeventloop。java:685)在io.netty.channel.nio.nioeventloop.processselectedkeysoptimized(nioeventloop。java:632)在io.netty.channel.nio.nioeventloop.processselectedkeys(nioeventloop。java:549)在io.netty.channel.nio.nioeventloop.run(nioeventloop。java:511)在io.netty.util.concurrent.singlethreadeventexecutor$5.run(singlethreadeventexecutor。java:918)在io.netty.util.internal.threadexecutormap$2.run(threadexecutormap。java:74)在io.micronaut.http.context.serverrequestcontext.with(serverrequestcontext。java:52)在io.micronaut.http.context.serverrequestcontext.lambda$instrument$0(serverrequestcontext。java:68)在io.netty.util.concurrent.fastthreadlocalrunnable.run(fastthreadlocalrunnable。java:30)... 1更多原因:io.netty.channel.abstractchannel$annotatedConnectionException:连接被拒绝:proxyhost/xx.xx.xx:3128原因:java.net.connectexception:sun.nio.ch.socketchannelimpl.checkconnect(本机方法),位于sun.nio.ch.socketchannelimpl.finishconnect(socketchannelimpl)。java:717)在io.netty.channel.socket.nio.niosocketchannel.dofinishconnect(niosocketchannel。java:327)在io.netty.channel.nio.abstractniochannel$abstractniosafsafe.finishconnect(abstractniochannel。java:336)在io.netty.channel.nio.nioeventloop.processselectedkey(nioeventloop。java:685)在io.netty.channel.nio.nioeventloop.processselectedkeysoptimized(nioeventloop。java:632)在io.netty.channel.nio.nioeventloop.processselectedkeys(nioeventloop。java:549)在io.netty.channel.nio.nioeventloop.run(nioeventloop。java:511)在io.netty.util.concurrent.singlethreadeventexecutor$5.run(singlethreadeventexecutor。java:918)在io.netty.util.internal.threadexecutormap$2.run(threadexecutormap。java:74)在io.micronaut.http.context.serverrequestcontext.with(serverrequestcontext。java:52)在io.micronaut.http.context.serverrequestcontext.lambda$instrument$0(serverrequestcontext。java:68)在io.netty.util.concurrent.fastthreadlocalrunnable.run(fastthreadlocalrunnable。java:30)在java.lang.thread.run(线程。java:748)
环境信息操作系统:aws ecs micronaut版本:1.3.4 jdk版本:1.8
我们用于连接aws sdk客户机中ssm的代理主机名相同,这些客户机可以很好地处理动态代理更改。这个问题基本上与micronaut和inetsocketaddress实现有关。请让我知道如何避免rxhttpclient在不重新启动应用程序的情况下缓存此代理ip地址
暂无答案!
目前还没有任何答案,快来回答吧!