我正在努力使用Micronaut HTTPClient多次调用第三方 REST 服务,但没有收到io.micronaut.http.client.exceptions.ReadTimeoutException
要消除第三方依赖性,可以使用调用其自己的服务的简单 Micronaut 应用程序来重现该问题。
控制器示例:
@Controller("/")
public class TestController {
@Inject
private TestClient client;
@Get("service")
String service() {
return "Hello World Service";
}
@Get("mproxy")
String multiproxy() {
StringBuffer sb = new StringBuffer();
for(int i=0;i<20;i++){
sb.append(client.getService());
}
return sb.toString();
}
@Get("proxy")
String proxy() {
return client.getService();
}
}
Run Code Online (Sandbox Code Playgroud)
测试客户端:
@Client("http://localhost:8080")
public interface TestClient {
@Get("/service")
String getService();
}
Run Code Online (Sandbox Code Playgroud)
使用curl、ab 或postman 直接调用/service 端点不会产生错误。
调用 /mproxy 端点将引发异常
ERROR i.m.r.intercept.RecoveryInterceptor - Type [clienttest.TestClient$Intercepted] executed with error: Read Timeout …Run Code Online (Sandbox Code Playgroud)