Reactive Programming

We continue to learn the Java functional programming paradigm in this chapter because some of the upcoming recipes will still require the APIs of java.util.function while building Reactive web components and Stream-based transactions.

This chapter discusses some of the new APIs needed to create Java events that are discrete, asynchronous, and non-blocking which are used in communication between a message sender and the recipient in many applications. This communication will eventually create a loosely-coupled and message-driven environment involving one or more Streams of Object. The model sounds similar to building message-driven transactions in Java Message Service (JMS) and Advanced Message Queuing Protocol (AMQP) but not exactly, since this communication model deals more with adaptive and scalable Streams of objects that can control data requests and even self-manage the data flow when bad data propagation occurs. When communication pitfalls happen, these APIs will just exit the data propagation without any exceptions as if nothing serious has happened. Moreover, these events are responsive in real-time given all possible requests and can somehow use the functional programming paradigm. This chapter will be all about building these kinds of events, which lead to Reactive programming concepts.

Reactive programming is needed mostly for transmitting or transferring a Stream of live data with no guarantee of zero transmission error and predictable data capacity. Its goal is to control the transmission of data to avoid traffic or starvation on either side of the transmitter and receiver. Since Streams play a great role in Reactive applications, these data transmissions are carried out using multithreading and concurrency techniques which can provide a non-blocking and asynchronous data flow even when data errors are encountered.

This chapter will highlight Reactive Stream APIs with the major inclusion of Project Reactor 3.x and RxJava 2.x. Spring 5 supports Reactive and asynchronous web applications that apply the mentioned Reactive tools in transforming and merging Streams of data using Java 1.8 JVM and above.

In this chapter you will learn how to perform the following tasks:

  • Applying the observer design pattern using Reactive Streams
  • Creating Mono<T> and Flux<T> publishers
  • Implementing the Subscriber<T> interface
  • Using java.util.function in Flux and Mono publishers
  • Applying backpressure to Mono<T> and Flux<T>
  • Managing task executions using schedulers
  • Creating concurrent and parallel subscriptions
  • Managing asynchronous data emissions
  • Implementing Stream transformation and manipulations
  • Testing Reactive data transactions
  • Implementing Reactive events using RxJava 2.x
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.101.109