目前,FluxProcessor訂閱僅檢索訂閱后發出的那些值。但我想在訂閱時檢索 Flux 中的最后一個值,例如,就像 RXSubject所做的那樣。我有這個設置: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期望的輸出:12
1 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
使用修復它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
添加回答
舉報
0/150
提交
取消