How do you use CouchDB change notifications to make continuous changes from Java?

I'm trying to use CouchDB (continuous) change API in Java and find that after exhausting the current change list, the flow seems to be closed rather than always open, as it should be

The code I'm using is as follows I hope I will never exit the while loop, but the streaming will be executed as soon as the current existing changes are completed I'm new to CouchDB and Java, so I may miss something obvious Can anyone tell me how to write this correctly?

URL url = new URL("[path to database here]/_changes?Feed=continuous";);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true); 
conn.setUseCaches(false); 
conn.setRequestProperty("Connection","Keep-Alive"); 
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line = reader.readLine()) != null){
    // do something with the line here
}
// Should never get here under normal circumstances
reader.close();

Solution

The actual default timeout is 60000 milliseconds (60 seconds) unless a different timeout value or heartbeat is provided I updated it in October_ Changes wiki page and contains any default values I encounter in the code

Setting the heartbeat basically means that you will observe the timeout on the client, that is, the heartbeat cycle does not wrap, which means that you must have lost your connection I believe CouchDB will disable its timeout check if there is a heartbeat

In any case, you should expect to close the connection at some point and write code for that condition

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>