我有PublishProcessor
连续发出值。我已经订阅了PublishProcessor
和两个订阅者,这两个订阅者在两个不同的线程上观察。当第一个订阅者持续收到onNext(T)
中的数据时,第二个订阅者在收到对Error: Could not emit value due to lack of requests
的几次调用后抛出错误onNext(T)
以下是我的实施
PublishProcessor<byte[]> publishProcessor = PublishProcessor.create()
dataFlowable.subscribeOn(Schedulers.newThread()).subscribe(publishProcessor);
Subscriber1的
publishProcessor.observeOn(Schedulers.newThread())
.subscribeWith(new DisposableSubscriber<byte[]>() {
@Override public void onNext(byte[] bytes) {
//Log.i("Sub1 ", "Data received");
}
@Override public void onError(Throwable t) {
}
@Override public void onComplete() {
Log.i("Record ", "complete");
}
})
subscriber2用户
publishProcessor.observeOn(Schedulers.newThread())
.subscribeWith(new DisposableSubscriber<byte[]>() {
@Override public void onNext(byte[] moreData) {
Log.i("Sub2 ", "Data received");
}
@Override public void onError(Throwable t) {
Log.i("Sub2 ", t.getMessage() + " "); // error received after few call to onNext()
}
@Override public void onComplete() {
Log.i("Sub2 ", "complete");
}
})
答案 0 :(得分:3)
这是MissingBackpressureException
。之所以发生这种情况,是因为发布商的生产速度快于订阅者的消费速PublishProcessor
不会将其下游订户的背压应用于其上游源。
什么是dataFlowable
?为什么不直接订阅呢?