简体   繁体   English

减少 Wildfly 连接超时

[英]decrease Wildfly connection timeouts

I have a problem with resource starvation on my java application running in wildfly.我的 java 应用程序在 Wildfly 中运行时遇到资源匮乏问题。 It is making a lot of API calls to other REST resources, and if one of these API:s is slowed down, our system goes down as well.它正在对其他 REST 资源进行大量 API 调用,如果这些 API:s 之一变慢,我们的系统也会出现故障。

It has happened that the backend systems are not responding within 14 seconds.发生过后端系统在 14 秒内没有响应的情况。 So I would like my application to break the connection after maybe 4 seconds.所以我希望我的应用程序在 4 秒后断开连接。 The "problem" is that we are using Client and ClientBuilder from javax.ws.rs.client and we are using wildfly as an implementation. “问题”是我们正在使用javax.ws.rs.client ClientClientBuilder并且我们使用 wildfly 作为实现。

So I have no idea how to set this timeout parameter.所以我不知道如何设置这个超时参数。 It doesn't appear to be possible from code, and I'm quite lost as to which wildfly subsystem is affected and what properties to set.从代码中似乎不可能,而且我对哪个 Wildfly 子系统受到影响以及要设置哪些属性感到非常迷茫。

Has anyone done this before and know how to set the timeout?有没有人以前做过这个并且知道如何设置超时?

So since wildfly comes bundled with resteasy you have to implement a timeout for that specific implementation.因此,由于wildfly 与resteasy 捆绑在一起,因此您必须为该特定实现实现超时。 That or force wildfly to use something else.或者强制wildfly使用其他东西。 Since forceing jersey upon wildfly didn't seem like the best of ideas(or the easiest) I went with configuring it.由于在 Wildfly 上强制使用球衣似乎不是最好的(或最简单的)想法,因此我开始配置它。

http://blog.eisele.net/2014/12/setting-timeout-for-jax-rs-20-resteasy-client.html http://blog.eisele.net/2014/12/setting-timeout-for-jax-rs-20-resteasy-client.html

import javax.ws.rs.client.Client;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;

 Client client = new ResteasyClientBuilder()
                .establishConnectionTimeout(100, TimeUnit.SECONDS)
                .socketTimeout(2, TimeUnit.SECONDS)
                .build();

and I've added the following in the pom.xml:我在 pom.xml 中添加了以下内容:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.0.19.Final</version>
    </dependency>

Given that both establishConnectionTimeout and socketTimeout are deprecated.鉴于已弃用建立连接超时套接字超时

With this explanation on jboss v7.3 by redhat website : redhat 网站对 jboss v7.3 的解释如下:

The following ClientBuilder specification-compliant methods replace certain deprecated RESTEasy methods:以下符合 ClientBuilder 规范的方法替换了某些已弃用的 RESTEasy 方法:

  • The connectTimeout method replaces the establishConnectionTimeout method.connectTimeout方法代替establishConnectionTimeout方法。

    • The connectTimeout method determines how long the client must wait when making a new server connection. connectTimeout方法确定客户端在建立新的服务器连接时必须等待的时间。
  • The readTimeout method replaces the socketTimeout method. readTimeout方法取代了socketTimeout方法。

    • The readTimeout method determines how long the client must wait for a response from the server. readTimeout方法确定客户端必须等待服务器响应的时间。

This worked for me with RestEASY 3.12.1.Final :这对我有用 RestEASY 3.12.1.Final

    private Client clientBuilder() {
        return new ResteasyClientBuilder()
            .connectTimeout(2, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .build();
    }
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.12.1.Final</version>
        </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM