Hands-On Reactive Programming in Spring 5
上QQ阅读APP看书,第一时间看更新

Fast producer and slow consumer

The second problem is much more complicated. Suppose we have a fast producer and slow consumer. The problem here is that the producer may send much more data than the consumer can process, which may lead to a catastrophic failure of the component under stress.

One intuitive solution for such case is collecting unhandled elements into the queue, which may stay between the producer and consumer or may even reside on the consumer side. Even if the consumer is busy, such a technique makes it possible to handle new data by processing the previous element or portion of data. 

One of the critical factors for handling pushed data using the queue is to choose a queue with proper characteristics. In general, there are three common types of queue, which are considered in the following subsections.