I've been seeing in Java the reactive streams concept which tends to standardize javaRX and Spring reactive concepts. Everything good except the fact that in order to do some transformation of the streams you need to implement one ore more processor. My question is regarding the need of the Processor interface Processor which extends Subscriber, Publisher
It seems that you passed a fun where you do the transformation and you couple it to both producer and subscriber and that's it ! But some questions arise:
- How do you handle the backpressure from the client/subscriber. If client ask for 10 elements you don't know in Processor how many elements you should ask further to Producer. I've seen examples asking for 1 or Int.MAX elements
- What's the fuzz about it ? Because from what i've observed it just carries a fun where you do the transformation, the fun is passed to the constructor and it is call later when the item flows through it (and that's it). So couldn't we've achieved this directly in producer or subscriber ? (i know that you want separation of concerns but you can eliminate problem 1)
You can see a basic example here: https://www.concretepage.com/java/java-9/java-reactive-streams . In the processor method onNext, you can see that processor asks for 1 element and this is bothering me: what about the backpressure from the subscriber side ? What if the subscriber asked for 100 elements once in a batch ? Shouldn't processor focus only on the processing side and it shouldn't asked for elements ?
@Override
public void onNext(Article item) {
subscription.request(1);
submit(function.apply(item));
}
Thanks !