问题
I'm trying to reactively tail a log file using RxJava-File:
File file = new File(".\\server.log");
Observable<String> newLines =
FileObservable.tailer()
.file(file)
.startPosition(file.length())
.sampleTimeMs(1000)
.chunkSize(8192)
.utf8()
.tailText();
newLines.subscribe(System.out::println);
and it works as expected. But as soon as I try to chain some more operators, I get problems. For instance, changing to
newLines.filter(LogfileWatcher::error).subscribe(System.out::println);
(where error()
is a simple function String -> Boolean
) I get output only after the first append to the file, but not the subsequent ones.
Similar problems appear when using window()
or several other operators.
What am I doing wrong?
回答1:
Backpressure support had to be fixed in rxjava-file and your test case is reported to be working as of rxjava-file 0.3.3 on Maven Central.
来源:https://stackoverflow.com/questions/32646260/rxjava-file-and-operator-chaining