I am new to the world of reactive programming and I am trying to create a simple backpressure aware message processing using rxjava 2.
Following is the workflow I am trying to achieve:
Flowable of a continues string stream.
Perform a time consuming operation and change the message to another string
Perform another time consuming operation.
Now I am using following code:
{
Flowable.create(subscriber -> {
some_stream.forEach(data -> {
subscriber.onNext(data);
});
}, BackpressureStrategy.BUFFER).
subscribeOn(Schedulers.io()). // Data emission will run io scheduler
observeOn(Schedulers.computation()). // Map operation will run on computation scheduler
map(val -> Time_Consuming_Task(val)). // Task returns another string
observeOn(Schedulers.io()). / Next consumer will run on computation scheduler
subscribe(val -> Another_Time_Consuming_Task(val));
}
Now for small operations I don't see any back pressure related issues.
But for large streams I don't know how it will behave.
Now My questions are:-
What is the default buffer size in case of BackpressureStrategy.BUFFER and where does the data gets buffered ?
What if I want to create two backpressure buffers, each before every time consuming task, should I use onBackpressureBuffer operator ?
If the buffer gets full, I don't want to lose data, I want to wait or something in that case ?