当前,FluxProcessor
订阅仅检索订阅后发出的那些值。但是我想在订阅时检索Flux中的最后一个值,例如,像RX的Subject
一样。
我有此设置:
FluxProcessor<Integer, Integer> processor = DirectProcessor.<Integer>create().serialize();
FluxSink<Integer> sink = processor.sink();
sink.next(1);
stateProcessor.subscribe(System.out:println);
sink.next(2);
输出为:
1
所需的输出:
1
2
答案 0 :(得分:1)
使用ReplayProcessor
修复了该问题。它能够存储N个最后发出的值以供进一步订阅。对于同一示例:
FluxProcessor<Integer, Integer> processor = ReplayProcessor.<Integer>create(1).serialize(); //1 is the history size
FluxSink<Integer> sink = processor.sink();
sink.next(1);
stateProcessor.subscribe(System.out:println);
sink.next(2);
打印:
1
2