Reactive Streams Specification

Pragmatic Code School
A free video tutorial from Pragmatic Code School
Technology Enthusiast, Online Instructor
4.5 instructor rating • 6 courses • 35,162 students

Lecture description

In this tutorial I will explain about what is reactive stream specification and which proivides the standard for reactive programming.

Learn more from the full course

Build Reactive RESTFUL APIs using Spring Boot/WebFlux

Learn to write reactive programming in Spring using WebFlux/Reactor and build Reactive RESTFUL APIs.

09:38:13 of on-demand video • Updated February 2021

  • What problems Reactive Programming is trying to solve ?
  • What is Reactive Programming?
  • Reactive Programming using Project Reactor
  • Learn to Write Reactive programming code with DB
  • Learn to Write Reactive Programming with Spring
  • Build a Reactive API from Scratch
  • Learn to build Non-Blocking clients using WebClient
  • Write end to end Automated test cases using JUNIT for the Reactive API
English [Auto] Hi everyone. Welcome back to this tutorial. In this material we'll talk about reactor stream's specification. What is a reactor stream in the first place. In the previous tutorial we talked about a data flowing as an event driven stream meaning requesting for data and the data flowing to the application as an event driven stream which is otherwise called US reactor stream. So now we know what is the reactor stream. What is a reactor stream specification a reactive stream specification is nothing but the specification are rules for a reactor stream to follow. If you think about object oriented programming we have principles such as inheritance encapsulation polymorphism and abstraction whatever code that we write in object oriented programming should relate to these concepts. Likewise this specification has rules on how the reactive programming code that we write should follow. Who created this specification. Engineers from major companies like pivotal Netflix light bend and Twitter and draw got together and created the reactive stream specification. So what does the reactor's stream's specification have the specification is very simple and it has four interfaces which are named as publisher subscriber subscription and processor. All of these interfaces talk to each other in order for the whole reactor stream to flow. Let's discuss about the interfaces one by one and finally I'll put it together so that everything will make more sense. Let's talk about the publisher first. This is a simple interface with a single method called subscribe which accepts the subscriber instance by making this call the subscriber registers to the publisher. Publishers are generally the data producers. Basically their data source. The examples of publishers or database are any of the remote service or anything external. The next one is the subscriber interface which has formats on subscribe on next on error and on complete. If you recall from the previous video we have already discussed about the on next on complete and on air and let me quickly explain the significance of these methods on next year's nothing but the data stream on complete is the signal for no more data on error even is a signal that some error happened. The only new method is the unsubscribe which has the subscription object as an input. What does the purpose of the unsubscribe method. You just gotta wait a little more to understand that. Next we'll talk about the subscription interface. The subscription interface has to meet its request and cancel. Now let's try to put everything together. I have a publisher at the top and a subscriber at the bottom. He can relate this to up pops up model. As I mentioned before publisher is the data producer are data editor subscriber is a one which is going to read the data from the publisher. Basically a subscriber is synonymous to consumer. OK now let's go through the floor diagram the numbers between the arrow represents the flow of evens it has a total of five types of evens strip. The subscriber is going to invoke the subscribe method of the publisher and as the instance of the subscriber as an input. After that the publisher is going to send a subscription object to the subscriber conforming the subscription is successful. If we are able to recall from the previous slide the subscription has two methods. One is the request and cancel. Let's talk about the request method for now and we will talk about the council in a bit. By default the request method is going to request for all the data whatever data that you have give it to me. Let's say the publisher is a database and it is going to read in hundred items. In that case there will be hundred on next. Even with each event representing a row will be sent to the subscriber. Once all the data is sent then we will be receiving on complete even that will be sent to the subscriber. There is an option for the subscriber to provide a number for the publisher asking for a specific number of data. If you take a look at it it takes a parameter and for example let's say out of the hundred matching items. You just need two of the items from the publisher. In that case you'll pass a value as to in the request call and then it is just going to give you two honest even and followed by that you will get the on complete even. Basically this concept is called back pressure. The subscriber has a control on how much data it needs from the publisher. This is one of the concept which I was highlighting in the prior videos. So there is a way for the application to talk back to the database. In our example here and requesting for the amount of data that it needs for processing. Don't worry about how to do that in the code we'll be covering all those scenarios in the future. But of course if there is any error in this whole workflow then we will be receiving an on error even Next we we'll talk about the cancel method and the subscription interface. The subscriber has the option to call the cancel limited and the subscription that is received from the publisher. The publisher a subscription rate it estimate that's 1 is a request method. That's what we have seen in the slide just before. This one is a cancel method. What happens after we call the cancel method. Basically what this means is we are canceling the subscription and the publisher is not going to publish any even to the subscriber. Next we'll talk about the processor interface. This interface is nothing but the combination of both the subscriber and publisher interface. That's why you do not see any specific methods for this one. I'm going to save the significance of this intro for use for the future part of the course. If we are still struggling to get your head around this concept just wait until we start recording part and start writing some examples. Then you come back to this video and watch it. It will make more sense then. So whatever we have seen until now is just a contract meaning they are just interfaces and just method declarations that are part of the reactive stream specification. We did not see the implementation of these interfaces. So in the next video we will talk about the reactive libraries which are the implementation of these four interfaces. Before we wind up I would like to show you where to find this reactive stream specification in the Internet. Let's go to Google and then in here I'm gonna search for reactor stream specification and then I'm gonna look on does it get to blink when I open it and the new top so does get up is the base for this reactor stream specification if you go a little bit down and read me. There you go you see the reactor's stream specification consists of the following parts. One is the FBI the EPA is the one which we discussed just no. Those are the four interfaces and the next one is their technology compatibility kit. Basically this is for the reactor library creators. The system makes sure the library whatever that you are writing is going to make sure it is going to follow all the rules that are part of the reactor stream specification. But this became for the end of the story. Thank you for watching.