对于我们的一个项目,我们使用java jersey客户机使用HTTP提要流
虽然客户端的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 chunkedInput = response.readEntity(new GenericType>() {
});
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();
}
}
如果流没有下降;线程必须在while循环中;一旦流关闭,线程就会出来并打印sysout语句
请帮我下决心;
在这里,对于服务器端的每个负载/块分离,它都是\r\n并且要使它与服务器的连接处于活动状态,请发送(在客户端,我必须忽略这一点)