Reactive Streams Specification

Pragmatic Code School
A free video tutorial from Pragmatic Code School
Technology Enthusiast, Online Instructor
4.5 instructor rating • 7 courses • 39,854 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 June 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 the studio to talk about reactor's dreams specification. What is a reactor stream in the first place? In the previous tutorial we talked about and data flowing as an event driven stream, meaning requesting for data and the data flowing to the application as event driven stream, which is otherwise called as a reactor stream. So now we know what is a reactor stream, what is a reactor stream specification? Reactive stream specification is nothing, but the specification are rules for 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 like voice. 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, Lightburn and Twitter and etc. got together and created the reactor's stream specification. So what is the reactor's streams specification have? The specification is very simple and it has four interfaces which are named as publisher, subscriber, subscription and processer. All of these interfaces talk to each other in order for the whole reactor's 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 the data source, the examples of publishers or database are any other remote service or anything external. The next one is the subscriber interface, which has formats on 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 error. And let me quickly explain the significance of these methods on next. Nothing but the data stream on complete is the signal for no more data on error event is a signal that some error happened. The only new method is the unsubscribe, which has the subscription object as an input. What is the purpose of the unsubscribe method? You just got to wait a little more to understand that. Next, we will talk about the subscription interface. The subscription interface has two methods request and cancel. Now let's try to put everything together. I have publisher at the top and a subscriber at the bottom. I can relate this to a pop up model. As I mentioned before, publisher is the data producer or data ammeter subscriber as a one which is going to read the data from the publisher. Basically, subscriber is synonymous to consumer. OK, now let's go through the floor diagram. The numbers between the arrow represents the flow of events. It has a total of five types of events. First up, the subscriber is going to invoke the subscribe method of the publisher and boss, 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 to admit that one is the request and cancel. Let's talk about the requirement that 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 return hundred items. In that case, there will be hundred on next event with each event representing a roll will be sent to the subscriber. Once all the data is sent, then we will be receiving an incomplete event that will be sent to the subscriber. There is an option for the subscriber to provide a number to 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 that you just need or two of the items from the publisher, in that case, you'll pass the value as to in the request call. And then it is just going to give you to our next event. And followed by that, you will get the on complete event, basically this concept. It's 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. They'll be covering all those scenarios in the future of the course. If there is any error in this whole workflow, then we will be receiving an on error even. Next, we will talk about the council method and the subscription interface. The subscriber has the option to call the council method and the subscription that is received from the publisher, the publisher since subscription rate it has to that's one is a request method. That's what we have seen in the slide just before. This one is a council matter what happens after we call the council. Basically what this means is we are canceling the subscription and the publisher is not going to publish any event to the subscriber. Next, we'll talk about the processor interface. This interface is nothing but a 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 interface for the future. Part of the course. If you are still struggling to get your head around this concept, just wait until we start the coding 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 declarations that are part of the reactor's stream specification. We did not see the implementation of these interfaces. So in the next video, we will talk about the reactor 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 going to search for reactor's stream specification. And then I'm going to click on this link when I open it in the new top. So this GitHub is the base for this reactor's dream 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 EBI. The ABA is the one which we discussed just now. Those are the four interfaces on. The next one is their technology compatibility. Get basically the source for the reactor library creators, the system, make 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 came to the end of this tutorial. Thank you for watching.