HTTP流与Java jersey客户端异常丢弃

Cre*_*tor 11 java jersey jersey-client

对于我们的一个项目,我们使用java jersey客户端来使用HTTP feed流

随着客户端Feed的消耗很好,但在10分钟后,流量异常下降; 即使流生产者已启动并正在运行并生成流

这就是我的尝试;

import java.util.Date;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ChunkedInput;

public class StreamClient {

    private static final String BOUNDARY = "\n";

    public void makeCall() {
        System.out.println("Start Time"+ new Date()) ;
        Client client = ClientBuilder.newClient();
        BasicAuth auth = new BasicAuth();
        auth.setPassword("username");
        auth.setUserName("password");
        BasicAuthentication basicAuthentication = new BasicAuthentication(auth);
        client.register(basicAuthentication);
        WebTarget target = client.target("https://localhost:7211/stream/v1/");
        Builder request = target.request(MediaType.APPLICATION_JSON);
        Response response = request.get();

        final ChunkedInput<String> chunkedInput = response.readEntity(new GenericType<ChunkedInput<String>>() {
        });

        chunkedInput.setParser(ChunkedInput.createParser(BOUNDARY));
        String chunk;
        do {
            if((chunk = chunkedInput.read()) != null) 
                System.out.println(chunk);  
        }while (!chunkedInput.isClosed());
        System.out.println("End Time " + new Date());
    }

    public static void main(String[] args) {
        StreamClient client = new StreamClient();
        client.makeCall();
    }


}
Run Code Online (Sandbox Code Playgroud)

如果流不下降; 线程必须在while循环中; 一旦流关闭,然后线程将出来并打印sysout语句

这里的问题是; 为什么chunkedinput被关闭了.

请帮我解决问题;

这里,对于服务器端的每个有效负载/块分离,它是\ r \n并使其从服务器激活连接,发送\n(在客户端,我必须忽略它.)

Rau*_*ero 0

我建议使用wireshark来分析连接丢失时的流量,很可能是防火墙正在切断连接。

无论如何,尝试在没有双面日志记录的情况下调试这些场景都是 50% 俄罗斯规则的情况。

如果您想放弃场景,请尝试改变正在传输的数据量、连接的参数(使用其他构造函数方法),并查看超时是否在时间上一致,超时是否取决于通常的流量量您触发防火墙等中间设备中某个阈值的线索。