我目前正在嘗試將MSF4J與StreamingOutput API結合使用。然而,我不想流式傳輸一個文件,而是想傳輸一系列無休止的短字符串/文本。我想立即將字符串刷新到客戶端。但是,客戶端在刷新後沒有得到它。我相信這是由於默認的8kb緩衝區,因爲我的字符串會在一段時間後被刷新。我如何覆蓋這個默認緩衝區,就像在glassfish中完成的一樣? https://jersey.java.net/apidocs/2.22/jersey/org/glassfish/jersey/server/ServerProperties.html#OUTBOUND_CONTENT_LENGTH_BUFFERwso2 msf4j:如何配置服務器屬性
我想是這樣......
Properties properties = new Properties()
properties.set("jersey.config.server.contentLength.buffer", 0);**
new MicroservicesRunner()
.setProperties(properties)**
.addInterceptor(new HTTPMonitoringInterceptor())
.deploy(new MyService())
.start();
我streamingout類
new StreamingOutput(){
public void write(OutputStream os) throws IOException, WebApplicationException {
while(true){
os.write("some string".getBytes());
os.flush();
}
}
}
謝謝。
因此,你的字符串立即得到flused,但不是int值是這種情況? –
@ThatithaThilinaDayaratne,整數也被視爲字符串,因爲它們通過REST返回。即使使用刷新,客戶端也不會立即收到字符串,直到8kb緩衝區被消耗完。 – Speng
你能分享全套服務嗎? –