Build Reactive RESTFUL APIs using Spring Boot/WebFlux | Dilip Sundarraj | Skillshare

Build Reactive RESTFUL APIs using Spring Boot/WebFlux

Dilip Sundarraj, Tech Savvy, Software Engineer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
85 Lessons (9h 10m)
    • 1. Course Introduction

      1:54
    • 2. Course Prerequisites

      1:03
    • 3. Why Reactive Programming ?

      8:58
    • 4. Traditional Rest API Design - How it works ?

      7:43
    • 5. What is Reactive Programming ?

      3:33
    • 6. Reactive Streams Specification

      7:57
    • 7. Reactive Libraries

      9:31
    • 8. Introduction to Project Reactor

      1:19
    • 9. Reactor Types - Flux and Mono

      7:30
    • 10. Project SetUp

      7:10
    • 11. Flux - How it works ?

      12:14
    • 12. Flux - Learn to write Junit Tests

      10:16
    • 13. Mono - How it works and write Junit Tests

      4:43
    • 14. Flux/Mono - Exploring Factory methods

      16:38
    • 15. Filtering a Reactive Stream

      4:26
    • 16. Transforming a Reactive Stream - map

      8:27
    • 17. Transforming a Reactive Stream - flatMap

      17:16
    • 18. Combinning Reactive Stream

      12:36
    • 19. Handling Errors in a Reactive Stream

      16:26
    • 20. Infinite Reactive Stream

      10:58
    • 21. Back Pressure - How it works ?

      14:22
    • 22. Project Reactor - Push/Pull Communication Model

      1:08
    • 23. Hot vs Cold Reactive Streams

      8:09
    • 24. Virtualizing Time in Junit

      8:58
    • 25. How to get help ?

      1:54
    • 26. Introduction to Spring Boot 2

      3:16
    • 27. Build the simple Non Blocking API - Flux

      9:33
    • 28. JUNIT : Test for Non Blocking API using WebTestClient

      15:54
    • 29. Junit : Test for infinite Non Blocking Sequence API using WebTestClient

      8:58
    • 30. Build the simple Non Blocking API - Mono

      4:07
    • 31. Introduction to Functional Web in Spring WebFlux

      2:12
    • 32. Build the simple Non Blocking API using Handler and Router Functions

      10:11
    • 33. JUNIT for Functional EndPoint using WebTestClient

      8:08
    • 34. Spring WebFlux - Behind the Scenes

      7:37
    • 35. Introduction to Netty - Channel, EventLoops

      6:57
    • 36. Netty - End to End, Threads, Execution Model

      6:31
    • 37. Application Overview

      1:53
    • 38. Setting up Mongo DB

      5:17
    • 39. Spring Profiles

      9:35
    • 40. Build the Item Document

      3:02
    • 41. Build the Reactive Item Mongo Repository

      2:00
    • 42. Reactive Mongo Repository operations using JUNIT - Read - Part1

      5:09
    • 43. Reactive Mongo Repository operations using JUNIT - Insert

      5:04
    • 44. Reactive Mongo Repository operations using JUNIT - Update

      4:49
    • 45. Reactive Mongo Repository operations using JUNIT - Delete

      8:24
    • 46. Build Artifact

      6:11
    • 47. Get All Items

      6:47
    • 48. Initialize the data using CommandLineRunner

      8:22
    • 49. Get All Items - JUNIT Test using WebTestClient - Part 1

      9:33
    • 50. Get All Items - JUNIT Test using WebTestClient - Part 2

      5:39
    • 51. Get a Single Item

      6:56
    • 52. Create an Item Endpoint

      6:08
    • 53. Delete an Item Endpoint

      4:31
    • 54. Upate an Item Endpoint

      5:18
    • 55. Upate an Item Endpoint - Junit

      9:22
    • 56. Setting up the Router Function and Handler Function for Item Reactive API

      2:17
    • 57. Get All Items - Functional Endpoint

      5:12
    • 58. Get All Items - JUNIT Test using WebTestClient

      2:53
    • 59. Get a Single Item - Functional Endpoint

      7:37
    • 60. Create an Item - Functional Endpoint

      4:35
    • 61. Delete an Item - Functional Endpoint

      3:29
    • 62. Update an Item - Functional Endpoint

      6:37
    • 63. Setting up the Item WebClient Project

      0:15
    • 64. Explore the retrieve() and exchange() in Webclient

      10:51
    • 65. Passing Path Variable using WebClient

      6:25
    • 66. Post call using WebClient

      5:38
    • 67. Put call using WebClient

      6:23
    • 68. Delete call using WebClient

      3:52
    • 69. Handling Exceptions in Controller - using @ExceptionHandler

      8:12
    • 70. Handling Exceptions in Controller - using @ControllerAdvice

      3:05
    • 71. Handling Exceptions in Controller - JUNIT

      2:47
    • 72. Default Exception Behavior - Functional Web

      5:00
    • 73. Handling Exceptions using AbstractErrorWebExceptionHandler

      6:40
    • 74. Handling Exceptions in Functional Web - JUNIT

      2:53
    • 75. Handling Errors in WebClient - retrieve()

      8:07
    • 76. Handling Errors in WebClient - exchange()

      5:07
    • 77. What is a Streaming EndPoint ?

      2:34
    • 78. Setting up the Capped Collection and new Reposoitory - MongoDB

      5:07
    • 79. Build Tailable Cursor using @Tailable Annotation

      2:27
    • 80. Initialize the data using CommandLineRunner

      6:43
    • 81. Build the Stream Endpoint using Controller

      5:28
    • 82. JUNIT Test for Streaming endpoint using Controller

      7:53
    • 83. Build the Stream Endpoint using Functional Web

      5:37
    • 84. JUNIT Test for Streaming endpoint using Functional Web

      2:38
    • 85. Use cases of Spring WebFlux

      1:10

About This Class

This course is structured to give you both the theoretical and coding aspect of Reactive Programming and Reactive RestFul APIs using Spring WebFlux.

If you are looking forward to learn the below listed things:

  • What is Reactive Programming ?

  • Write Reactive Programming code with Spring WebFlux.

  • Write Reactive Programming code with DB.

  • Building Reactive RestFul APIs with Spring WebFlux

Then this is the right course for you. This is a pure hands on oriented course where you will be writing lots of code.

By the end of this course you will have the complete understanding of coding and implementing a Reactive API using Spring WebFlux.

Why Reactive Programming ?

  • This section highlights about the need for reactive programming and explains in detail about the current execution model in spring-mvc.

  • This sections explains about the drawbacks in spring-mvc.

  • This section explains about the concurrency model in spring-mvc.

What is Reactive Programming?

  • This section talks about "What is Reactive Programming ?"

  • How Reactive programming works in a nutshell using a simple example.

  • This section will give you all an introduction to Reactive Streams Specification.

  • This section will give all an introduction to "Reactive Libraries" that are out there.

Getting started with Project Reactor

  • This section will give you all the fundamentals of Project Reactor and explore the project reactor using some examples.

  • This section covers the Reactive Types Flux and Mono in detail.

Setting up the Project for this course

  • In this section we will set up the project for this course using the Spring Intializr website.

Reactive Programming (Flux and Mono) - Hands on + Junit Testing

  • In this section we will explore about how Flux and Mono works via code.

  • We will do live coding on how to write Junit test cases using Flux and Mono.

  • We will explore lot of different operators in Flux and Mono.

Build the first Non Blocking RESTFUL API using Annotated Controllers - Hands On

  • In this section we will build the first non blocking API using the annotated controllers.

  • This section covers the fundamentals of how the reactive API works.

  • This sections also covers the coding aspect of how to return a Flux/Mono from an end point.

  • This section also covers how to write JUNIT test cases using WebTestClient.

Build Non Blocking RESTFUL API using Functional Web - Hands On

  • In this section we will build the non blocking API using the Functional Web Module.

  • This sections explains about the RouterFunction and HandlerFunction which forms the foundation for Function Web Module.

  • This section also covers how to write JUNIT test cases using WebTestClient.

Spring WebFlux & Netty - Execution Model

  • This section explains about the different layers behind WebFlux to serve a HTTP Request/Response.

  • This sections covers the concepts of NETTY such as Channel, EventLoop and some of the technical aspects of Netty.

Overview of the Reactive API

  • This section will give you an Overview of the Reactive API that we are going to build as part of this course.

Reactive Programming in Databases - MongoDB - Hands On

  • In this section we will learn about how to write the reactive programming code with MongoDB.

  • Define the Item Document for the project.

  • This section covers about how to configure different profiles in Spring Boot.

  • In this section we will set up the ItemReactive Mongo DB adapter.

  • This section also covers how to write JUNIT test cases for the reactive repository.

Build the Item Reactive API Endpoint - Using RestController

  • In this section we will learn about how to code the Item CRUD Reactive API using the @RestControllerapproach.

  • This section also covers how to write automated tests using JUNIT and the non blocking test client WebTestClient.

Build the Item Reactive API Endpoint - Using Functional Web

  • In this section we will learn about how to code the Item CRUD Reactive API using the Functional Webapproach.

  • This section also covers how to write automated tests using JUNIT and the non blocking test client WebTestClient.

Build Non Blocking Client using WebClient

  • In this section we will explore the techniques to interact with Reactive API using the WebClient.

  • Learn the techniques to Invoke the Reactive API using exchange() and retrieve() methods.

  • We will explore the GET, PUT, POST and DELETE operations using the WebClient.

Handling Exceptions in WebFlux - RestController

  • In this section we will code and explore different approaches to handle the exceptions/errors that occurs in the reactive api that’s built using RestController.

  • Handle exceptions using @ExceptionHandler and @ControllerAdvice.

  • This section also covers how to write JUNIT test cases for the Exception scenarios.

Handling Exceptions in WebFlux - Functional Web

  • In this section we will code and explore different approaches to handle the exceptions/errors that occurs in the reactive api that’s built using Functional Web.

  • Handle exceptions using WebExceptionHandler.

  • This section also covers how to write JUNIT test cases for the Exception scenarios.

WebClient - Exception Handling

  • In this section we will code and explore how to handle the exceptions using the WebClient.

  • Learn the techniques to handle the exceptions using exchange() and retrieve() methods.

Streaming Real Time Data using WebFlux - Server Side Events (SSE)

  • In this section we will code and learn about build an endpoint for Streaming RealTime Data using Mongo DB and Spring WebFlux.

  • This section covers about the Tailable Cursors and Capped Collections in Mongo DB.

  • Build a Non Blocking Streaming Endpoint and interact with the Mongo DB using the @Tailableannotation.

  • Learn to write Automated Tests using JUNIT for the Streaming Endpoints (SSE).

Transcripts

1. Course Introduction: Hi. I really want to thank you for taking your time to view this video. My name is Dileep on. I'll be your instructor for this course. I'm a software engineer and I have been building software's since 2008. I've been teaching online since 2016 that struck aboard what will be covered in this course . This course will give you all an understanding off reactive programming contextually and programmatically. This course will also cover the need for reactive programming on the problems. The reactor programming is going toe. So followed by that, we will explore the project reactor, which is a reactor programming library after dark will be building to react, arrest full E p ice using spring the flux. We will be writing the or emeritus cases using Jane it for each line off court that we will be writing in this course who is a targeted audience. Anyone who is willing to loan about reactive programming can enroll in this course. Anyone who has the interest to loan and build the reactive AP ice are welcome toe enrolled in this course. I guarantee you that you'll be doing tons of courting in this course This is a pure Hansen oriented course. All the source code for the scores is available and get up on the sore score is also attached. In this course, it's a feel free to subscribe to. My YouTube channel called With the Leap where I have been actively uploading the content related to Java. Springboard on more. My goal is to upload lots and lots of technical content in this YouTube channel. Going forward, make sure to subscribe so that you get all the greats from my and I hope to see all in the journey off building the reactive rescue. AP Ice using spring plucks a very big thank you again for taking your time to be of this video. 2. Course Prerequisites: Hi, everyone. Welcome back in this video, I'll explain about the prerequisites that are needed to make the most out of this course. You need to have knowledge about spring boot to understand all the concepts that will be explained in this course. On top of that, if you have experience building rest ful AP ice using springboard. That would be great. I'll be using the job eight features such as Lando's and Streams in the course. So if you have experience with it, then that's an advantage. If not, don't worry about it. I have a course on this topic. Modern Java Loan Job. Eight features by quoting it and have a coupon attached to this course. You need to have at least Java Gerica eight installed in your machine. I'll be using intelligent this course, so you need tohave either in Italy J R. Any other equal and I d like a clips are not beans or extra, but this We came to the end of this video. It's time to start our reactor Spring journey. Thank you for watching 3. Why Reactive Programming ?: hi. Everyone will come back to this tutorial in this tutorial will talk about why reactive programming is needed before we jump into the reactive programming part. Let's talk a boat, how the programming in general have a walled and what is a current state off programming. Let's go back 10 to 15 years ago, the application that we used to build was a giant monolith applications. The applications run in application servers. This model does not embrace the distributed systems at all. Let's talk about the current state off the applications we are living in the world off. Micro services Micro services embrace the cloud infrastructure where the applications will run in the cloud environment, and it also embraces the concept off distributed systems. To put it in a nutshell. The application that we build today is split into micro applications and in track together in real time to deliver the business objective. The weapon use age in general is increased compact toe 10 to 15 years ago, and the expectations off the app that we build also changed. Let's take a look at the expectations for any up that we build today. The application should scale according to the Lord. What do we mean by that? Let's say we haven't online shopping application. If the number off users increase than expected value, then the application should scale its resources to handle the Lord. Basically, there shouldn't be any downtime. Use the resources efficiently. What do we mean by that? Let's say you make a call to the database. Are an external service to get some data, and during the scenarios, we wait until the responses returned from the external resources. Bearing on something in general is not effective. Resource. It glaciation. We'll be talking about this in detail in the future. Part of the course, the next key characteristic is a laden sea waters Layton see laden. See is nothing but the response time off the request. The response time should be faster to meet the customer need. So the a P I should perform as fast as possible. Now let's switch gears and talk about how the request and response flows between the client and the server for any app that's built. Using the spring. NBC and Springboard Spring Emmys is a model that we use today in spring to build Arrest a B ice. I have the floor diagram off the traditional tourist FBI on how it receives a request from the client and how it sends response back to the client. This is just to brush up the knowledge on how the request and response is handled. In spring, NBC In this floor, I graham the numbers between the Iroda presents the flu off evens, which starts with one and ends with seven. Now, let's talk aboard the different layers that 30 Bricker's goes through before the response is sent to the client. When the client makes http requests the request comes to the server, which has the embedded tomcat by default, which is nothing but the server container. In this case, the server container has a dedicated threat pool toe handle the http request for each http request Be a senator. This model is called threat per request model. This particular thread is responsible for handling the request in to end. The next layer is a filled earlier on. Then it goes through the dispatcher subject layer on. Then it goes to the request mapping handler mapping leader. They're the call is actually directed to the controller, which has the appropriate You are mapping and then it goes through the service layer, and then it connects student database. Once the results are retreat, then the service layer applies some kind of data transformation, and then the response will be sent to the blind. The example that they presented here and the slide has a DB as the back and let's go and take a look at the next example. So here all the comforts are the same, except the back end is a external FBI service. Instead, offer remote database, and I have one more other type off the FBI's that people today is the combination off remote database and remote FBI seven. The client makes a call. We talked to both the external services to collect the data based on the request and then send the response to the blind. Predominantly. These are the three common partners that are available in today's wrist. AP ICT development. Now let's talk about the next interesting topic. How the traditional rest full FBI's handled a concurrent request. The model that we have today is a threat for request model. For each http request, the Tomcat is going to take a thread from the threat pool and assigned the thread. So that http request each allocated thread is responsible toe handle the life cycle of that . Http request. As you see in the example, the treads can be extended one Lito value off and which is nothing but the threat. Full size. Because doctors a one which is going to decide how Maney number of concurrent users can be handled at any given time. How can we increase our decrees that triple size? There is a handy property that can be used in our to manage that value. The threat Full size is managed by the server dot com car dot master its value, so by default it can handle 200 connections. So in TV, it can handle only 200 concurrent users. And this value can be overdone in the application or property files are application or yama file and the springboard application. Just because we have an option to over it, the value does not mean you can set a larger value for the property. Let's understand us on the memory aspect. Each thread takes up some memory. The common stock size is one MB so hired the triple size, higher the memory conception just for the threat instance itself. What will happen in that case is art. If you have a larger threat, pull basically That leaves you but very less memory for the application processing, which eventually means the application will perform poor. Hardly make sure the application scale and handle the load. Today there are many ways to handle the Lord, but the most popular approach that is done today is by using a resulting scaling. This means we will spin up more instances of the application based on the Lord. So here in this example, we have three instances off the application. Basically, this means the Lord is three times more than the expected value. That's the reason why we have three instances up and running here. So how can this happen? How can we achieve this if your application is running and some kind of Cuban orders are some other container orchestration environment, then this is a possible in real time. We will have a load balancer sitting in front off our application, which will take it off. Distributing the http request toe the applications. This model works perfect and this model will work in the future toe. But if you take a look at it, spinning off more instances in the cloud is going to add some kind of additional cost to the organization. So what does what frickin summaries is dark. We have a limitation when it comes to handling many concurrent users, but but reactive programming? The idea is to move away from the trip a request model on handle the Higher Lord Off request with less number off hurts. Let's talk about more in detail aboard how this can be achieved in the future. Part of the of course. I want to discuss something important before we wind up this video. Does this mean the traditional rest ful FBI's that we have been building for so many years ? Or obsolete? The answer is no. Doesn't mean all the FBI's that we have been building today should be moved to a new model , which is not the Triple Request model. The answer is no. This morning it works perfect for many use cases, and many FBI is in the future, will be built with the same design and supported have some more aspects off why reactive programming is needed in the next tutorial. But this we came to the end of this tutorial. Thank you for watching 4. Traditional Rest API Design - How it works ?: Hi. Everyone will come back to this tutorial in this tutorial will talk about some of the other aspects of the traditional rest api I that we have today. Let's start with the traditional rest API I design and find out how it works. Here is an example off a traditional wrist FBI in point. Let's talk a little bit of boat. This endpoint the FBI that we have here relates to the retail industry. This endpoint gets the idea as an input from that line on. Then returns the response entity off type item item As to additional details, one is a price and the location where this item is available to return the item with all the information. First we make a database call and get the price of the item and then we make the rest call to get the location where this item is available, and then the build item together with the price and the location information that we got from the service and respond that toe the line. This kind of coding is called imperative style. According on the A, P, I is called imperative style AP I where the execution goes from top down approach. What do we mean by that? Here we made the rebels call, followed by that. We made the first call to get the location. We go one by one. And then we had Bert the item and responded that to the plane. Imperative style. The FBI's by its nature. They are synchronous and blocking. Let's dig deep to understand what we exactly mean by that. In this code, we make a database called right after the remote Davis call is made. We have toe Vaid until the responses. Let's see from the database. Let's take a look at the same concept, enough flow diagram. So here we got the request and then we got a thread assigned to that request by the Tomcat and we made the call to the database. So after the collars made, we are in a state called blocking state. Basically, the thread doesn't do anything until the response is received from the database. What this means is that imperative style of programming leads toe in efficient use off resources. This is one of the problem, but the rest api a design. So if you go back to the court here, we're block and then once the responses received, then we make the call to the rest for the FBI and then return the response to the client. Now let's talk about the synchronised aspect off the traditional FBI. Let's assume the Laden Sea off this end point us to milliseconds. The Davis call takes one millisecond, followed without the rest. AP a call takes one millisecond, which sums upto two millisecond. Here we have a simple use case, but in reality you might be doing a lot off external resource calls before responding to work. Clients request. Let's say you want to improve the response time off this in point, then we need to make these calls asynchronous. Basically, what does it mean? We need to make these calls non blocking? How can we do that? Currently, in Java, we have two options, callbacks and future. Let's touch base on these options callbacks by its nature, their conflicts and they're not a great option. Callbacks does not return any value, but it does take the instance off call back as a parameter. The callback code as a nature off handling exceptions at each level on the court itself is hard to read on meeting, it will quickly lead to a famous tomb call callback. Hell, let's take a look at the future option. The future is another Al Canedo for asynchronous court in Java. Future returns the future instance, and we can use the future instance to check whether the readers available. We have hand emitters to call and check whether the Raiders available or not, but it's hard to compose the multiple asynchronous operations with feature. Considering these limitations, we haven't advanced future FBI that God introduced as part of a Java eight, which is the comparable future. Certainly the comfortable future FBI is simple to work with, and it has the support for the functional style FBI. It is easy to compose the multiple asynchronous request, but comfortable Future is not a great fit for asynchronous myth. It's which involves multiple items in the response, and the error handling is not that great, too. So we need to do a lot of plumbing to make it work, right. So it is not easy to improve the late INSEE with the traditional rest API, a design which uses the imperative style off programming. Let's take a look at another example this endpoint returns a list of items. Consider some of the top retail chains such as Amazon, Alibaba, target our WalMart. And if this endpoint is going to return all the items in the inventory, then think about the response object size. And if this endpoint is bombarded with many request, then as a result off those two things can happen. This might blow up the heap, and application might crash with or off memory. Exception are the client will be provided with such a huge response, which the client might not be able to handle. So I would like to highlight one more aspect before we get into the summary part. How to be a wide dust from happening if there is a way for up to communicate to the source , which is DB in the scenario on profit of feedback. Hey DB, can you slow down? You're sending too much data on I'm not able to handle it. Please slow on. This concept is called back pressure. Don't worry about it for novel will be discussing this concept in detail once we get into the reactor programming. But but with the imperative sale of programming are with the imperative style AP Ice. The APP does not have a way to communicate to the DB two slower on our reduce the size of the payload. So no back back pressure compatibility in traditional rest. EPA design. Let's summarize what we've discussed so far. Fast. There is a limit on serving the number off concurrent users. They are synchronous and non blocking and imperative style. The FBI's requires a lot of work to do in order to make it asynchronous, and the last is there is no back pressure support. That doesn't mean the traditional AP I design is not recommended. The answer is definitely no spring muc model will still be part of the spring ecosystem and continue to be supported and enhanced Traditional rest API I designed fits for many use cases, so we'll be continue to burled Doris Filippi eyes in the future, too. Now let's talk about what is a better FBI designed then fundamentally asynchronous and non blocking move away from the Threat per request model used fewer threats to serve many request and back pressure compatible. Let's talk about what is reactive programming on how reactive programming is going to solve the limitations that we have with the traditional rest AP A design in the upcoming tutorials. Don't worry about the fact that they did not start. And according I just wanted to set up the stage before we actually get into the courting part so that all the topics that we discuss will make more sense. But this we came to the end of this tutorial. Thank you for watching. 5. What is Reactive Programming ?: Hi. Everyone will come back to the cereal industry. Tutorial will talk about the popular reactor libraries on the library that we're going to use to write the reactor program in court for this course. So what is the reactor library? In general, it is nothing but the implementation off the reactor streams specification, which is nothing but the publisher, subscriber subscription and processor. So, one of the reactor libraries that we have today, we have our eggs, Java reactor and Jericho itself as the flow class, which includes the reactive streams. Specification. So, out of all these options, what is a library that we're going to use for this course? Okay, we are going to use the reactor, which is nothing but Project reactor project reactor is built on maintained by pivotal. Basically, the team behind the spring and spring boot project reactor is a default library that comes with spring Good for writing reactor programming court or building non blocking rest full. AP ice in spring. Let's go ahead and check. What do we have in Project Reactor? So I'm gonna go to Google under in search far project reactor. So there's a length look on this bus link. So this is the home page for the project reactor. Let's look at some of the things that are highlighted here. Reactor is 1/4 generation reactive library, far building non blocking applications on the JV Um, based on the reactive streams specification and they have the reactive core reactor is a fully non blocking foundation with efficient demand. Management it directly in drugs with jar functionally API. I complete herbal futures stream and duration will be exploring examples on all of these in the future part of the course, and the next important thing is that type sequences. They have flux and mono. These two are the fundamental thing, which we need if you're going to work with Project Reactor will be exploring Dart. Also in the future, part of the course non blocking I owe. This is perfectly suited for micro services architecture. Reactor offers back pressure. Ready network engines for http will be exploring that also in the future part of the course . If you go a little bit down, you can read through all these things, and they have a very good documentation. Let's click on this reference guide If you go to the reference guide. This reference guide is very neatly documented. And if you want to know anything about Project Reactor, this is the place to go and the documentation is very were boys. And it covers a lot of areas that are needed in order to get yourself more comfortable with the project reactor. And they have a active community also, if you want to, just if you want to just connect to the community, you just goto this link and then argue risotto this group. So this is one of the community where if you have any doors or something can reach upto this community, they will healthy are so we'll be exploring most of the content that is there in this speech in the next section. But this became to the end of this tutorial. Thank you for watching 6. Reactive Streams Specification: Hi. Everyone will come back to this tutorial in this tutorial Will talk about reactor streams. Specification What is a reactive stream in the first place? In the previous tutorial, we talked about our data flowing as an event driven stream, meaning requesting for data and the data flowing to the application as a event driven stream which is otherwise called US reactive stream. So now we know what is a reactor stream? What is a reactive stream specification? Reactive stream specification is nothing bought. 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 court that we write, an object oriented programming should relate toe these concepts. Likewise, this specification has rules on how the reactor program in court that we write assured follow who created this specification. Engineers from major companies like pivotal Netflix light bend on Twitter and ex cetera got together and created the reactive stream specification. So what does the reactive streams specifications have? The specification is very simple, and it has four interfaces which are named US publisher, subscriber subscription and processor. All of these interfaces talk to each other in order for the whole reactor stream. Toe flow. Let's discuss aboard interfaces one by one on. Finally, I'll put it together so that everything will make more sense. That's DACA border publisher First, this is a simple interface with the single method called Sub Scrape, which accepts the subscriber instance. By making the skull the subscriber registers to the publisher. Publishers are generally the data producers, basically their data source. The examples off publishers are database. Are any of the remote service or anything external? The next one is the subscriber interface, which has form it. It's on. Subscribe on next on error and un complete. If you recall from the previous video, we have already discussed a boat, the on next on complete and on error. And let me quickly explain the significance off these methods on next to nothing. But the data stream on complete is the signal for no more reader on error even is a signal that some error happened. The one Lee new materialism on subscribe, which has the subscription object as in input. What is the purpose off the unsubscribe? Minted, you just gotta wait a little more to understand that next we'll 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 subscriber at the bottom. It could relate this to a pops up model. As I mentioned before, Publisher is the data producer. Our data emitter subscriber is the one which is going to read the data from the publisher. Basically, subscriber is synonymous to consumer. Okay, now let's go through the floor diagram. The numbers between the IRA represents the flu off evens. It has a total of five types off evens faster up. The subscriber is going to invoke the subscribe matter off the publisher and passes the instance of the subscriber as an input. After that, the publisher is going toe. Send a subscription object to the subscriber, confirming the subscription is successful. If we are able to recall from the previous light, the subscription has two methods. One is the request and cancel. Let's talk about the request minted for now, and we will talk about the cancel in a bit by default. The request Minter is going to request for all the reader. Whatever data that you have given to me. Let's say the publisher is a database on it is going to written 100 items. In that case, there will be hundreds on next, even with each even representing a row will be sent to them. Subscriber. Once all the data is sent, then we will be the saving on complete even 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 our of the 100 matching items you just need to off the items from the publisher. In that case, you'll pause. The value is two in the request called and then it is just going to give you to our next, even and followed by that you will get the incomplete. 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 their prayer videos. So there is a way for the application to talk back. Do the Derby is 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 court will be covering all those scenarios in the future par of the course. If there is any error in this whole workflow, then it we will be receiving an on error. Even next, we'll talk about the cancel method and the subscription interface. The subscriber has the option to call the cancel minted in the subscription that is received from the publisher. The publisher Sensor subscription, right? It has two minutes. One is a request. Minted. That's what we have seen in the Slight just before this one is a cancel. Minted what happens after we called the cancel Minted. Basically, what this means is we are cancelling the subscription on the publisher is not going to publish any, even though the sub scraper next we'll talk about the processor interface. This interface is nothing but the combination off 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 off this intra fees for the future part of the course. If you are still struggling to get your head our own, these concepts just wait until we started according part and start writing some examples. Then you come back to this video and watch it. It will make more sense than so. Whatever we have seen until now is just the contract. Meaning they are just interfaces and just method declarations that are part of the reactive stream specification. We did not see the implementation off these interfaces. So in the next video, we'll talk about the reactive libraries, which are the implementation off these four interfaces. Before we wind up, I would like to show you where to find this reactor stream specification in the Internet. Let's go to Google and then in here I'm gonna search for react. Oh, stream specification. And then I'm gonna click on this, get a blink when I open it in a new top. So this get up is the base for this reactor stream specification. If you go a little bit down and to read me There you go. You see the reactors stream specification consist of the following parts. One is the FBI, the a P a is the one which we discussed just No. Those are the four interfaces on the next one. Is there technology compatible etiquette? Basically, this is for the reactive library creators. The system. Make sure the library water world that you're writing is going to make sure it is going to follow all the rules that are part off the reactor stream specification. But this we came to the end of this tutorial. Thank you for watching. 7. Reactive Libraries: Hi. Everyone will come back to this tutorial. In this tutorial. I'll give you all an introduction to reactive programming on the concepts that form the foundation off reactive programming. Quick note. Here. This section is going to cover purely a boat waters, reactive programming in general and how it works. I'm going to save the discussion about reactive AP eyes for the future part of the course as you need the reactor programming fundamentals in order to build the reactor. AP ice. So what is reactive programming? This is a new programming pattern. Time on it is going to be a complete shift from the baby have been building things in Java . The definition ask for the documentation is that this programming style is fundamentally asynchronous and non blocking and a data is going to flow as an event driven stream. Don't worry. If you're not able to wrap your head around what it means, you just gotta wait a little bit more. I'll be discussing about these concepts in detail and reactive programming provides functional style AP Ice just like the Stream FBI that got introduced as part of our eight. And it also supports back pressure on the event driven leader streams. We touched on this topic a bit on one of the previous video. We'll discuss more in the future part of this course in this light. Let's understand how the reactive programming works. Using a simple example Here I have two friends texting each other friend one and front toe . For the sake of this example, let's assume friend one is watching TV and friend to is busy outside with this family for a dinner friend. One decides to text friend toe in reality after the messages sent friend, one is not going to wait and block until the response is received from this friend aspect. Example here after the Hey, what's off? Messages sent from friend one basically a friend. One is gonna continue watching TV. This kind of communication is called asynchronous and non blocking the ideas and not overweight and block on anything. Now friend to came home from his dinner after some time and gets the chance to respond to a friend. One with the message just came back from dinner, and they continue the conversation in a similar fashion, which is asynchronous and non blocking. Once they're done with the conversation. They're going to do what they were planning to do. In addition to the asynchronous and non blocking aspect, this kind of communication is called a message. Are event driven communication. So in a nutshell, this is how reactive programming works. Now let's get into the detail off how the data is going to flow as an event driven stream. In reality, let's take a look at an example. Before we get into the reactor programming part. Let's quickly touch base on. How does the data is going to flow in that imperative world, the court here uses GP makes a call to the database to retrieve the data. In reality, the left side represents the AP and the right side of Persons area TV's. First, we make the call to the database to get the leader, and then basically the APP waits before it gets the data from the renovation. It goes into the block and waiting state, and in this example we had retrieving the list of items from the database so we will be blocked until the complete list off items are retrieved. This is a very have been courting for many, many years, and Java This programming model is also called a synchronous and blocking communication model. How does this work in the reactor programming world in reactive programming world, as I mentioned before, the data is going to flow as an event. Our message Stream your quick. Not here. When I say even our message both refers to the same thing. So basically, the data is going toe flow ascent event stream. So we're going to receive one. Even for every resort item from their data source, The data source could be, ah, database or an external service or an external file are ex cetera. Once all the data is event it out to the collar, then we're going to receive a completion. Even if there is an editor and retrieving the data from the external source, then we're going to receive an ever even. I understand this concept is totally new, and it is really hard to get your head around this concept. No, that's take a look at the same concept that I explained. Using a floor diagram, Dr will give you a good understanding off. What do we mean by event driven stream? The query here is going to retrieve a list off items from the database. The real source that I have here in this example is that database say it could be anything . Basically it could be external service or a file or anything like that. So the faster because we're making the call to retrieve the other stuff items. As I mentioned in the example, the call returns immediately. The reason being this is a synchronous and non blocking. The interesting behavior is that the data will be pushed to the application as a stream on as it is available one by one, meaning one even for every single item in the result set. As you see here, we receive our next call from the rubbish layer to the application layer for every single item and this will be continued until all the items are pushed to the application. This data flow is called event driven stream basically are not being blocked and the data is pushed to the application now, once all that it has pushed the receiving even called on complete. That means hey have pushed all the items. Here is an on completion, even which tells you I don't have any more data. Don't think too much about the internal details off how it's going to work. I'll be covering all those concepts in the future tutorial. For now, let's focus on how the floor works in general Water showed you here is a happy path. Let's talk about the unhappy part where some kind of error after the retrieval, we make the call to the database as like the previous example on the called returns immediately after the first result item after the first on next call, which gave you the first item because of some reason, we got an exception in that case instead off abruptly exiting the execution floor, which is how the imperative programming style works. Here it is going to send you and every went to let the application know something unexpected happened. So after this even has received, we can take it off handling how you want to recover from that exception. Now let's talk about the noted off law there for a given search. Corey. There is no result than in that case, we just get the incomplete even from the Davis layer. Now let's talk about the same floor with return type is void. The example here makes a call to the database to save the item in those kind of scenarios, if the safest successful they get on complete, even our if the say vis unsuccessful for some reason, then we get an on error. Even so, this is how the data flows in the reactor programming world. So in a natural, there are three things when it comes to data communication and reactive programming. Number one on next four Data stream evens number two is on complete for dear completion. Even number three is on error. Far better. Even so, fundamentally, this is what we need to know when it comes to reactor programming. It will be exploring all these in court in the future part of the course. Now let's take a look at the next aspect of reactive programming, which is the functional style Court. Reactive programming embraces the concept off functional style court. If we have worked with Java eight Streams, FBI, then you might be able to relate what I'm talking about. The court that we write and reactive programming makes it easy to work with Lando's. Here is an example of the court that we will be writing in the future part of the course. The example that we have here is a put and point their talks to the DB on perform some kind of transformation operations and returns the response to the client. Don't worry too much about the court. At the moment we will be building the reactor non blocking rest ful in points in the future . Part of the course. Let's talk about the next aspect of the reactive programming, which is the back pressure. Reactive programming supports back brochure. If the reader sources producing more data than we expected, then there is a way for the application to provide a feedback to the reader source stating unit a slowdown until a catch up. This option is handy when it comes to build stable systems using reactive programming. So we talked about the different aspects that form the foundation off reactive programming . We will dig into the details off how all of these concepts can be implemented using court in the following tutorials. But this we came to the end of this tutorial. Thank you for watching 8. Introduction to Project Reactor: Hi. Everyone will come back to this tutorial In this tutorial will talk about the project reactor on the different models that are percent and project reactor. Let's go to the home page and then check the different models that are available and project reactor. Have the browser open, and I'm gonna go to the home page Who are the home page? Click on this documentation link. When you go to the documentation link. This is there. All the different models that are supported by Project reactor is available. So if you go a little bit down reactor core reactor, test reactor extra react unity and it has four or five more. Our goal for this course is not to explore all the models that are present in this project reactor. For this course, we're going to explore the following models. I'm gonna go back to the presentation and then show you the models Reactor core reactor test on reactor Nitti. These are the three more deals that will be covered as part of the scores and these are the three models which are necessary in order to build the non blocking reactive rest ful AP ice. Let's go ahead and explore these models in the falling tutorials. But this we came to the end of this tutorial. Thank you for watching. 9. Reactor Types - Flux and Mono: Hi, everyone. Welcome back to this tutorial and this tutorial will talk about the reactor core library from the name offered. We can say this is the core library off project reactor. This library has the implementation off the reactive streams Specification. In order to work with the reactor core, you need at least job eight running in your machine. Let's dig deep. Undercut the implementation off the reactive streams. Specification. We have seen this program in one of the previous video on. We talked about how the reactor stream should flow on the different types of evens that are involved in it flux and mono or the two classes which are the implementation off the the actor streams Specifications in Project Reactor These are the only two classes which you need to know in order work but project reactor These are the reactor types off project reactor flux is a class which presents zero toe and elements. Mano is a class which were present zero toe. One element there talk about specific use cases on them to use mono and then to use flux in a bit. Let's start with flux. The reactive types in project reactor are explained using the marble diagrams. We have the marbles at the top and then operator in the middle and then marble diagrams at the bottom so the marble diagrams of the top represents the actual data on the operator in the middle represents the filtering transformation. A lot of other operations to transform the data from its raw form. Toe another form. It goes through the operator layer one by one, and then the marble diagram below represents of final output, which will be sent to the subscriber. The vertical line here represents the incomplete human meaning. There is no more data. I'm done. But the request. There is no more data to send to you and the X year percent. There is some kind of error happened in one of the elbow evens to summarize the whole flow . So we have this marble magnets at the top, which is going to flow one by one, which is going to be passed to the operator earlier one day one, and then the final output will be sent to the subscriber. Let's take a look a quick example, and then I'll show you the documentation on this one. So the example here is like we have a flux off three elements. In reality, we might be pulling this data from our database and our to keep this example simple. I have this flux created using this adjustment. It This is one of the baby can create a flux. Don't worry about it. For now, we will be exploring all these in the courting examples. What happens is this flux has three elements, and all these elements will be sent one by one. So the map here is one of the method which is part of the reactive FBI, which is going to convert the spring to spring flux and spring boot to springboard flux and then react to spring boot to react to springboard flux. Basically, it happens. The string flocks to the elements in the flux, and then we have the subscribe attached to what? This is nothing but the subscriber and the use cases. Really simple. We're just printing over here that some razors. So you're going to get the spring spring book and reactor springboard us each and every element passing down to the next layer, which is the map layer in the my player were just can calculating the flux to the each and every element on. Then it goes to the substrate mattered and in the substrate matter to keep this example simple, we're not doing any additional activities. We're just printing that value. No, let's go ahead and take a look at the documentation for this flux. Go to the browser. Let's type in Project Reactor clucks, and then it takes you to this. I want to go to the browser search results and then come on here. So project reactor flux and then click on this fast. Link this page as a complete information about flux. If you remember, this is a marble diagram, which we just discussed. And then if you go a little bit down, these are the different kinds of methods that are supported by the flocks FBI. When it's a matter, these are the different operators. So we saw the map mattered in our example, right, like Wizard has lots and lots of methods, and he can chain many different operators to follow pipeline toe. So that's a very normally court will be exploring all those examples in the future part of the course, but for no, let's take a look at one of the example. I'm gonna take this buffer in Max Ice as an example. If you go here, we have, in this example the top layer of persons actual data, as they explained, and then in the before What we have is Maxie's of three. So it's going to buffer until the size is reached and then it's going to send the airport. AZA combined are put off three elements to the subscriber. And if you take a look at what we have won the five So here after the two elements we received the incomplete. Even so, the buffer is smart enough to know Hey, I I'm not going to receive any more apt for this. So I'm going to combine those two us our put and send it to the subscriber. So these marble diagrams are handy and you can refer to each and every operator that we have here. And then the marble diagrams will give you a pictorial presentation off how it's going to work. So this is all about flux. Now let's go ahead and explore the model. It's called the presentation. Mono is the presentation of 0 to 1 element, actually, so here. If you take a look at it, we have one marble at the top and one marble at the bottom. So that's what is more knows about after this one element we're going to receive on complete. Even so, they exceed a percent. Some kind of error happened. And, uh, model so mano is a use case. Let's say you are requesting for only one data from a database are one the one data from ah , Restaurant point. So in those kind of cases, you can use moral. Whenever you see more than one element, then we will use the flux. Now let's go to the example. So here, this example is similar to the one which we discuss for the flux. So here we have Mono Dart just say just and then won the one element You cannot provide multiple element as an input. So this just matter if you're using mono, if you do that, you're gonna get compilation issues followed by that we are performing the map operation, and then we are transforming the original value to spring to spring flux. And then we have a subscriber to hear that. So you are touching subscriber and then we are printing that value in the council just for the simple use case we have here. So in the future will be discussing more complex examples The afternoon enough theory about Project Reactor and it's implementations. Let's go ahead and explore these in the court and the following tutorials. But this we came to the end of this tutorial. Thank you for watching. 10. Project SetUp: Hi. Everyone will come back to this tutorial in this tutorial. We're going to set up the project for this course. The faster Plus. We're going to go to the spring Initialize er website. I'm going to type and start. So I said I say type the start. I got the recommendation as start dark spring dot I've ongoing contact. So this is a website which we're going to use in orderto build a base springboard project. So the project which we're going to pull its going to be a grill project. I'm going to select the griddle on the current bush in that I have here is two point one point toe. So this is a version, which is the latest version. When I recorded this video, I'm gonna name this group. Name us com dot alone reactor spring. So that's a group name. I'm gonna click on this switch to full version, and I'm gonna name the artifact idea as loan dash reactive spring. Okay. And then I'm gonna keep the package name as com dot alone. Reactive spring on the job of ocean. That amusing is Java eight. So Java eight is a beast version for springboard toe. So now we need to select the dependencies. We're going to build non blocking GPS, right? So in that case, we need to select the reactive. So if you take a look at it, there is a reactive development with Nettie and bring that looks correct. That followed by that the DB component that we're going to use its among or TV. I'm going to select reactive mongo db Derek O. And followed without what we're going to do. We're going to select Lahm book as a dependency. Okay. And after that, we're going to select embedded mongo db So embittered Mongo DB is for writing integration excuses. Once we're done with that, what we're going to do, we're going to click on the Generate project a button. As soon as we click on this click generate button, it's going to give you a zip file. So we're going to go to the location off that pile. There you go. I'm going toe Unzip this one. Normally, when you double click on the fall, it's going to give you the folder. Have a different extractor and zip extractor, so I'm gonna click on this extract button. There you go. I have the project. The next opus, I'm going to import this project into the into the J. Have they included open monocle Kanda Import project and I'm going to go to the downloads folder. And so, like this one and click open. And we're going to use import project from external model and then select the griddle because that's the bill it'll that we're using as part of this project. Click next. I'm gonna use the used auto import, and I'm gonna sell adoption for create directories for empty continent roots automatically . And I'm gonna leave rest of the defaults on the job of ocean. They're amusing is Java 1.8. That is a minimum that is required in orderto run a springboard to project. And then I'm gonna look on the finish. I'm gonna put it on the full screen moored There you go. I'm gonna closed us. So it's don't luring lot of differences if you take a look, whether it is running a lot of background process is basically when you don't let this for the very first time, it might take some time to down there all the dependencies, in order to set up the project for you. In the meantime, what I'm going to do is I'm going to expand this project. So you see this. Build our grill find right. This is a file which is like a bombed or maximal. If you are using her maven project, you are welcome to use me even if you want. Because on the dependency on the bill, it'll and this very, very minimal work. It won't be touching this file often. So if you want, you can use maybe into when I select this file, zoom in a bit. So these are the dependencies Dark V selected from the springboard initialize er page to take a located. The Mongo reactor spring the started will clocks, which is the reactive web. We have the Lombok and just gets added automatically. This is the embittered mongo DB. And in addition to that, we have something called Project Reactor. Project reactor is a default reactive library that comes with spring. The flux on the default server is going to be nitty. I'm going to expand this external libraries and then I'll show you the project reactor divinities Research for Project Reactor. There you go. We have three dependencies. One is a project reactor core which has all the flocks and mono reactive types. And other one is a reactor that is for testing the flux and mono. Because you cannot just write this to you. Notice cases like the they you have been writing before in our protest the non blocking sequences. They have given us our specific reactive library for that. And followed by that we have this reactor, Nettie. So this is a rapper which is bird on top off nitty in our for dignity. To understand the flocks and mono reactive types, we have one final task before we complete the project set up. So we have this lahm box selected rate. We need to enable Lombok for this workspace. The faster bus you need to check whether you have the lumber plug in, look honest, intelligent, and then select the preferences. So first thing you need to go to the plug ins search for long book. So as soon as a search for alarm, I have the Lombard plugging normally few because I heard it before in my workspace itself. If you did not have this, you have toe. Look on. This blows repositories button, and then you'll see this one. So you need to click on the little being installed. Martin. In the place of a break, you have to install this and restart the intel ET. So how the Lombard plugging already available? The next up is I need to enable this for this particular project. How do we do it? I have to search for connotation. As soon as a search for an irritation, you get this option called enable annotation processors and this option will be unchecked by default. So you have toe check this one on, then click OK, Either our play button will be enabled, or you can click. OK, By making this, you are enabling the lumber plug in for this project so you can use the Acela 40 annotation . You can use all those Lombard related connotations for this project. But this we came to the end of this tutorial. Thank you for watching 11. Flux - How it works ?: Hi. Everyone will come back to this tutorial in this tutorial will explore a boat, flocks on mono hundreds internals, wire cord. My approach to master the reactor types flux and mono is by writing the test cases and learning from it. The first thing is, we're gonna expand this this folder and then expand the Java package and then the com dot loan reactive spring package. What I'm going to do, I'm gonna create a package called Flux and Mono the Ground and then click OK, and we're going to create a Huskies. The desk is Name is going to be flux Onda mono just me change the stopper case and then click. OK, so now I'm going to zoom in a little bit. The next thing is, we're going to create the best method that PSA next thing. So I'm gonna create adjustment Did called public wired blocks. Just changes went to lower case. So we have the best case ready. The next step is we're going to create the flux. So in our notice, the flux we need the flux right that's going and created flux has a handy method called just which takes in the parameters So what I'm going to do, I'm gonna pass three strings in our to keep this example thing simple. I'm gonna create a flux off three elements Spring, spring boot and reactive spring. So this is a flux off three elements. In reality, this might be the flux which is flowing from the dead, obviously. Er, for now, to give things simple, we are basically building this flux. I'm gonna give it a name for this flux. So there's a flux off type string, and then the name is going to be string flux. So there's a flux, uh, maximise this. There's a flux off type string. Now we have the flux, right? The only way to access the elements from the flux is by subscribing to it without subscribing. There is no point of having a flux, and it is meaningless now. The next step is we're going toe. Use the reference of the lux, which is string flux dot substrate. So then you subscribe 0.0.7. You are actively attaching a subscriber which is going toe read all the values from the flux, the new subscript. That's when the flux is going to start emitting the values to the subscriber. The subscriber has many versions offer many overloaded versions offered. The first thing is, we're gonna just get the value and print a value in the console. So what I'm going to do, I'm going to use System Doc out. Colon, Colon, friend Ellen. So I'm just reading the values from the flux and then printing it. Let's go ahead and run this one. So to run the this case in intelligence, you have to click this icon and then it gives you the option called Run flux. Just you have to click on that option. When you do that, it's going toe Brinton Valis one by one. So as soon as you subscribe, what this flux does as it's going to pause the elements to the subscribe, which is the subscriber off the flocks one by one. So it guard the values one by one and then printed the values in the console. Now the next thing is, let's say if there is some kind off ever happened. In that case, how do we know? So in that case, subscribe has ah older version off handling dark, so it takes in ah, second parameter to the subscribe omitted, and then it takes in the exception. And you can handle the exception in whatever way you want. So in the imperative programming, what do we do? We handle the exceptions using their try catch. So in here, as part of the substrate minted itself, you can posit exception and are exception will be handled to keep things simple. I'm just gonna print the exception here system dot It a dot Ventolin And then it is. There you go. No, I want to attach any toe the flux how we do it. So flux has a hand emitted Kalkan Catlett When I use that couldn't get with and I'm gonna are that exception So you have to do flux dot ed if when you do this basically you are throwing an exception and using the concocted we are attaching that exception to the flux. Basically, the original flux, which is the string flux in here? We will not have the exception ash new runtime exception and then pause the other message and a message us exception. I could right now let's it on this example Lyrical. So regard that exception also has anyone, if you remember from the previous lights. The data is going to flow to the subscriber as evens. As soon as you call the sub scream. It'd a subscript, even the sent to the flux. And then from there it is going to send the evens using the ah next mentor and pause element. Or and then when there is an exception, it's going to send you the on air. Even with the exception, it's all anti right hold of, you know, is it really happening? In order to make sure that we're seeing all those evens what I'm going to do us, I'm gonna add a log flux as a handy method called not log. This log is going to log all the evens that happens behind the scenes when you call the sub scream Inter, That's good. And run this all right on this as soon as you 100. Now, if you take a located, the lager is huge, right? Let's go and explore what's happening there. Let me see whether I can zoom in. There you go. I'm able to zoom in the faster bus on subscript. That's what the scholars and followed with art. There is ah on request call, meaning the records called with unbounded. Basically the subscribe request for Gimme. Whatever data you have, the unborn did relates to long, dark max value, So that's a value. It is requesting the flocks to Emmett as soon as it receives the flux reserves. The request on Bordered call. It's going to send Element one by one. That's why you see the on next on next. And then it pauses element. And then we're printing it here, right? And after that it's gonna pause a springboard on our further. It's going to pause the on next, since we have ah, enter here. That's the reason why it ended with on Earth. In your usual cases, if there is no error, then we're going to receive their own complete even. Now what we will do, we will go ahead. I'm gonna common this on. Then let's run this example again. So instead, off on error, we will be having the on complete even. And then we are logging this exception here like Java lang dart around time exception, which is exception occurred. So I'm gonna just start some more longer. Here, exception ists. This is to make sure our exception block captured the exception went on this again. So if you take a look at it, there is an exception. Because I have commented out this line. That's the reason where you just see the incomplete. So this is how the internal working off flux on the subscription works. Saxena's you subscribe. It's going toe, make a subscript called and then the request call. The subscript call goes to the flux and the request call goes to the flux. So basically, we receive a subscription, but it is not shown in the Logar. But I'll explain that in a bit. The request call is going to cost for all the reader. That's when you receive all the even right as on using their own next. Mentored from the flux, the flux is going toe called called on Next Mattered in the Subscriber. And then it's going to pause elements one day, one and then the uncompleted. No, I'm gonna uncommon this one from this again. There we go. We have the exception, and the exception ist exception occurred right Now, let's go ahead and check one more scenario. I'm gonna add one more element called Concocted It. This is going to be after the honor or even just limited the use case that I'm going to show here is that after the other does the flux still emits element to the subscriber or not? So let's use flux dot Just I'm gonna are after terrorism string. Let's go out and run this and then check. So I'm expecting I'm not expecting the on next, even for the after. That's good and run this Did he receive dark after ever know the reason being once an editor is emitted from flux, that's it. It is not going toe send you any more data after that. So that is something which we have toe keep in our mind. So we added this right, Let's check. Do we have this value printer under control? Copy this, and insurgent here their ego. So whenever we have an exception, it goes to this block and then it has the message that we added, and then the actual exception itself the sacrament it takes in another parameter. That parameter is just to have the on complete. Even whenever there is an uncompleted one that gets notified what I'm going to do, I'm going to use the lander and then Let's Prince on this issue completed. So let's go out and run this one. That search for this one. Do we have competed in the console? No, we do not. Because our frocks ended within better. I'm gonna come on this line. Did he go? And then I'm gonna run this. There you go. Regard this completed message printer and the consul. Basically, this block gets executed whenever there is a complete even from the flux. So this is to make sure whenever you want to do some kind of activity after the flux terminated, meaning the flux is fractures. No more data toe, Emmett. Then in that case, you can use this doored parameter as part of the sub screaming. So you might be wondering. We explored all the internals and how the data flows from the flocks to the subscriber. Right now, we didn't write any excuses. Actually, discusses, basically is ah didn't assert anything on it. Right? So Reactor just has a model dedicated for testing these foxes. So testing the flux is totally different from the way we have bean according so far in Java . So I'll be showing you the techniques on how toe test of flux in the next tutorial, But this we came to the end of this tutorial. Thank you for watching. 12. Flux - Learn to write Junit Tests: Hi, everyone. Welcome back to the sectorial in this tutorial loan about the techniques of writing the test cases that is going to assert on the elements that are part of the flux. I'm gonna open the this class flux on monetarist when I zoom in a little bit. And then let's go ahead and write, Duh. This case, I'm gonna name this one asked Public Wired Lux dust flux just elements and then without error. So I'm not gonna have any error as part of the flux. So what I'm going to do, I'm going to just copy this first line and then put it here, followed by that, I'm gonna add the lock. So we have the flux really rate. The next thing is, we're going to does the elements inside the flux, which is spring, spring boot and reactor spring, and then the order in which the elements are flowing to the subscriber, right? No. In our protest elements, reactor test is a model that we're going to use. It has a class called Strip. Very fire. Let's create an instance off it order. Right? I mean, it's called the class and then it has omitted. Called creed. All right, For this method, we're going to pass the flux. Okay, That's good on the next purpose. What is that we're expecting? It's going to run this. I'm going on. Uh, I'm gonna hold on to those and then run this and then check waters that were printing. So this is a test which we wrote in the previous video in here. If you take a look, er the foster rally with spring, the next value spring boot and the next values a reactor spring. So that's what we have in our flux rate. So the step very fair has handed, but it's like dot expected next. So in the expect, next you can provide spring. That's a faster value that we expect. Right? So that's the first value. The flux is gonna him into the subscriber. And then the next thing is, what is an X value? It's going to go. We'll minimize this so that the court will be clear like this. There you go. And then the next thing this it's gonna be spring boot. So I'm gonna put the put the spring. But here, right, let's put the double courts and followed without what the next. Well, you expect next and the next valuers reactor spring. So I'm gonna put that value also here. So let me former this. There you go. Now what we will do, I will try to run the Huskies. And then what is the last? Even if you take a look at it, Since there is no error, we're going toe. Have the verify complete, right. That's the last even call, the very fake complete. That's when the actual data is going to float. Okay, now let's go around around us particular good. The discus past. And then all the evens are flowing, as expected, just for the sake of from making sure this works is expected. What I'm going to I'm gonna change order and then see what happens. So when we change the order, the expectation is that we want to make sure this just fails. That's called and run it. There you go that this case failed because we changed the order. The expectation nous spring boot. But it failed with the value spring. So this disk is make sure we are getting the elements from the flux in the order that we have it here So the difference between these two is that here we call the subscribe omitted rate. The substrate minted is one which is going completely, which is going to start the whole flow off the flux Topaz elements from the flux to the subscriber. But in here, if you take a look at it, the step very fair takes care off, subscribing to the flocks and then asserting the values on the flux. So it is very fake complete. If we do not call what happens, What I'm going to do is I'm gonna come in this and then show you what happens if we do not make a call to verify a complete what happens. Let's go ahead and then this. You see here eight, we do not have any evens flowing from plucks. The reason being verify complete is a call which is actually equal into sub scrape. That's a one which is going toe actually start the flow off elements from the flux. So you have to make sure all this you end of the day s case with verify call. Right now. Let's go and explore the next month it which is flux, just elements. Vit better so I'm gonna put with it. And what I'm going to do is I'm gonna use the can Catlett, which we have here. Let's copy this and then put it here so they can carpet is gonna add the exception, right? And then here we are actually expecting the verify, complete as the last even. But that's not the case here, because very free area is going to be the last. Even because we have the expected exception added to our flux, let's go out and run this basically this chest is gonna feel, but still, I want to show you what happens when you run it. So the expectation nous expect complete at me zoom in a little bit the expectation ISS expect complete, but the actual is on it. Right? So how do we write this case is so that we can assert on the exception. So does a hand emitted called? Expect So put a dot I expect and it so if you take a look at it, expect it it and then you can give one time exception dark glass. So here the exception type runtime exception. That's the reason why I'm putting the expect error on the type of the exception as a argument toward the very fate complete won't work because very fake complete doesn't make sense. Here we are expecting the editor rate. So in that case, the materials that are available to us is just really fight. That's going to call this verify because very far is the one which is gonna actually start the whole flow off flux from the flocks to the such Graber. So here the step. Very fight of the subscriber. Right? Let's go ahead and run this disc piece. We're under this case, their ego. It gave you the green signal, meaning that this case is working us expected. Let's say you want to just very frayed the message inside the exception. So in that case, there is a handy matter also available for that. So we're gonna do expect Mrs Diego, expect error message, and then we can pass the string as an input so that expect error message, and then that's good. And run this they regard and gave it the green signal, meaning that this case worked as expected. If you can, we have both of these. The answer is no. You cannot have both together. Let's go out and run this one more time. There you go. So now let's say you don't wanna validate all the values. You just want to validate the number off elements. That particular flux is gonna Emmett. So in that case, water will do. So I'm gonna create another mother. I'm gonna copy this whole method and then put it here. So I'm gonna name this one us. That's maybe is this flux elements? Flux elements count. So you just want toe? I saw it on the number of elements. Right. So the step pretty fair has 100 method for that called expect next. Going down so in the county will pause the value us three and then followed by that aspect , our use case. We have exception. That's the reason why I have the expect error message, Toby. Exception occurred. We run this, it's gonna work is expected. There you go. And I'm gonna show you one more variation here. Flux dust with it. Only flux test with it of so here we have. I'm gonna name this minutes. Everyone here we have expected next as separate lines. Right? You don't have to do what you can do us. You can just put everything in a single line toe like this and followed with that. You can do the reactive spring. What? I'm going to dio I'm going toe remove these lengths and I'm working on this. We're under, so it's gonna give me the green signal. The reason being this is one off the other way off asserting on the elements in the flux. So these are the different approaches off testing the element in the flux. There are somewhat wants to use cases which will be testing in the future tutorials. But this we came to the end of this tutorial. Thank you for watching. 13. Mono - How it works and write Junit Tests: Hi. Everyone will come back to this tutorial in this tutorial with court and explore the mono reactive type. Let's go ahead and open the flux and Ma noticed. And then what I'm going to do, I'm gonna create Ah, this case called at just on the name of the test case is going to be public. Lie it, mano. Just so we have the best case ready. Now let's go ahead and create the instance off. Mano. So mono has a handy method called mono dot just. It just takes one value, right? Because mono by its name from the previous slide, if you can remember monaural presents one element starts The reason why you do not have the option to pause multiple elements. Flux has the option to pause multiple elements. That's the reason why we were able to create a flux with multiple elements. Now I'm gonna pass just spring and then let's give it a name is gonna be a monologue off type strength. All right. And then this is a string model. So we have ah, monologue instance created. Now let's go ahead and just this one. So the Veda district iss, by creating the step very fire and then call the create, mentored and then pass the string model. So the approach is similar to whatever we wrote for flux is the same approach. And what is that we expect we expect next. The next value is basically spring. So he removed a cold in here and then followed by that we're going to expect the on complete even dot verify complete. So you want to see whether these evens are happening right, So you can call a log matter here. So basically, after you have a flux Armando, we can add methods in the create instance also. So now I'm gonna go ahead and run this one if it unders can take a look at the longer the logger, the first callers on subscribed. That's what this very famous there is going to do and followed by that you request for on Boehner data. But in mono, it's always going to be only one data, right? So we got the next even which is on next from the mono and then the UN completely event. That's what we're doing. An artist case. Also, we are sitting on the element and then the actual compression even. No. Let's go and explore the editor. Even for some reason, my ankle Ajax Weird. So I'm gonna name this one as mono. Just it a So I'm not gonna do a monitor. Just because Montoro presents only one element. What I'm going to do, I'm gonna We'd the mono dot era directly here mano dot error So it accepts the trouble. What I'm going to do, I'm gonna create an instance off new runtime exception. And then that's Gibson Commons exception. A good. And then it's gonna be what it's gonna be very if I it. Right, So it's gonna be expected the eight object it off type. I'm gonna just also on the pipe or just a one time exception Dark class. And followed by that, we need to make the call to the verify other voice. The mono will not emit the elements to the subscriber. Now let's go ahead. And under this case, as soon as you run the test case, there we go. My printer, the value. One interesting thing you might notice. Why do not say any longer your rate Because we didn't call the log minted here. If you call the law, Guittard. That's when you will notice all the evens that are flowing between the subscriber on the mono Jericho, you have all the evens you make a call to on subscribe, request and forward way that we caught the on error even from the mono. And then we asserted on it. Somalia is really simple. And what does became to them and of this tutorial? Thank you for watching. 14. Flux/Mono - Exploring Factory methods: Hi. Everyone will come back to this tutorial, and this material will explore some of the other factory methods that can be used to create flux and mono for this purpose. What I'm going to do, I'm gonna create a glass called Flux and Mono Factory just and then click. OK, I'm going to zoom in a bit. The first step is we're gonna create under I estimate that I'm gonna create the estimate that US dust public lie it flux using. It's horrible. So we're going to create a flocks out off the list that medically, the other lists of the class of them so that I can reuse it for all the methods. All the distributors in this dis case. And then what? I'm going to dough. I'm gonna declare this one us. Let's start string. I'm gonna give it a name. Us names. That's got an import. This one. Okay, so the import is gonna be job Bardot, You tell. That's option. I'm going to select, and then it's going to be are raised dot us. List us. I'm gonna pause the names us, Adam. And then I know Next thing us. Jack and Jenny so have four names on the list. I'm going to create a flux using this list. How do we do? It looks as a handyman that called flux dot from a terrible and then pas the names as a input. So as soon as this particular statement is executed, we're going to get a flux as a response. That's going to be a flux off strings, right? Do that flock soft strings, and then the name is going to be names blocks. So we have, ah, flux Created from a realist. How do we very fade out? So I'm going to use a step pretty for year dot greed. And then I'm gonna positive flux or here. Right? So we can advise the until a streak and only passed the flux. So I'm gonna remove this. Yes, there we go. And then we were What is that we're going to expect we're going to expect on all these values, right? I'm just gonna copy this and then put it here and followed with that. We are going to expect that Verify complete even. There you go. Now, let's go ahead and run this one. I'm expecting a green signal. That means that it's caught this case executed successfully. So in order to see water, all the evens that that happened behind the scenes you can use log. It's not monetary to put the log for each and every flux that you create. But in case if you're interested in no from the events that happened behind the scenes, then go. And at this, somewhere on this again, there you go. It printed the values in the console. So zoom in a bit. The first thing is on subscript even from the strip Very fire and forward without a request treatment from the strip. Very fire, which is which is like you are a subscriber requesting for data from the flux. And then the flux caused the data one by one, using the our next myth it to the subscriber and forward without regard the on complete even. No, that's great. One more this case flux as another handy factory method, which is called a flux. Using a fax from Marie, I'm gonna use that to create a flux public wired flux using buddy. Okay? No, we're gonna create a string theory. I will not give it a name. Names. It's go to not this equal to new string and forward without let's pause in the names. So I'm just gonna copy this from here on deposit. So we have the string are a created right. The next step is we're going to use the fuck's dot from take a look at it. We have the from parameter. I'm gonna use that method, and then I'm gonna pause the names. There you go. So now we have the flux. Ready? Let's give it a name. Flux off string and forward without we need to give a name. So I'm gonna give the name us names. Flux. There we go. We have the flux created, and I thought would be that It's the same thing. I'm gonna populace. Same step. Very fair, not create an imported here. It's gonna work as expected because it's the same data. Same order that they're out here. But understand it's gonna give me a green signal. There you go. Got executed as expected. No, there is. A next method which we're going to explore is a stream matter. So stream is ah, FBI, which cord injuries as part of Java eight. You can create a stream from a collection. So the collection that we have here is a list of names, and then we will deposit stream as an input and then create a flux are offered. So I'm gonna create the dismissed it and the name, this one US public wired flux using stream. And then I'm gonna create the flocks using stream. Right. So that's great of flux off upstream. It's gonna be named us names. Flux, he called toe. Now we'll call the flux God from stream. There is omitted call from stream and then we're going to pause the names list dot stream. So when you call the stream with it, it's going toe actually fast that as an input to the flux mattered using the stream, the flux is going to get created now, right? The step very fire. An arctic eight things simple. I'm just using the same example. If you want to explore different examples, you are welcome to do that. And if you get stuck with any kind off road blocks, please be sure to me I'll be able to help your so step very fire dot greed and then passing the names flux followed by that, we're expecting the same are put. So I'm going to use the same data and forbid are it's going to be very fine complete. There we go and we're understand. Then I'm gonna expect just a guinea, a green signal. That means we have clear of flux using a stream. So what happens here? Us here, Verify, complete as soon as we call the very fate complete. Basically, the stream is going to start emitting the data. You know, Right stream is now seems like a lazy evaluation unless and until you are called terminal operation, which is part of the stream, it is not going to send you the data. So as soon as we call the very fate complete, the stream is gonna pass the element of the flux one by one that is going to create the flux and pause the elements to dips a subscriber one by one. So we have seen a lot of extreme with a lot of fact LTD's for flux. Now that's going explore some of the Fact LTD's for our model. Okay, let's go ahead and explore the first factory motive for mono. It's going to be just public. Lyon on the name is going to be model using just our empty. So this is one of the factory monitored which we can use to create a mono reactive type. Morneau dot Just rmt so in here. What it can do is you can pause either The valid value are unknown value. We have already seen examples passing a valid string. Now what? I'm going to don't get a personal so many personal what you're going to get us. You're going to get mono God empty. So it just like empty model. That's what you're going to get as old put. So that's going and give it a name. I'm gonna give it a type. Is Mona not string? That's fine. Mano is a name off this flux. Now we have the mono created that's going create the step very, for instance, and call the create matter and pause in the model. So many bodies. Amano What is that we're expecting, actually, so this morning is gonna be an empty mono, right? So in that case, you cannot do expect you can only do verify complete. So it is not going to emit any data because nothing is there to Emmett, right? So it just to show you what I'm going to dampen out the log here. That's good. And run this one, Jericho. So the first collars on subscribe and the request call from the subscriber, and you just received the UN completely went from the model. Okay, Now let's go and explore the next myth. It just public, public wired mano using some there. So some player is a functional interface that got introduced as part of Java eight. We want to see what its A player search for some player. I'm Mr. I hear. There we go. We just part of the job about little dot function if you click on it. This is a functional interface, which just has this myth it right, that's gore and create the implementation offered. So first, that's creator implementation of Star Player. Yes, a player is something which doesn't take any input. I'm gonna create a supplier of type string, and then that's important. This Jabara, you do not function all right. What many Mr. So that court is clear. And then I'm gonna name this man as strings a player, and then we just the equal go so it doesn't take any input. I'm going to use the lander, and then we're going toe returned. The So this a player whenever you call, basically this is going to return you the string, right? So, mono off type string, And then I'm gonna give it a name called String Mono. It's going to be model dot from supplier, right, that cemetery, which we're going to call some player. And in here, we're going to pass string some player. There you go. So it's automatically going toe. Get the value, Adam. As soon as we call the Stephanie fire not create and expect the value. And we paused A very fair, complete minted. So step very fair. Got create string model just for the sake off Looking at the evens I'm gonna create the log called the dogmatic and followed by that what we do, we're going to do expect next. So what is the value that we're going to expect? We're going to expect Adam, right? Let's pause that one ReMax misters and followed by that What is that we're going to do? We're going toe call a very, very complete method. Right. So this is what we're expecting. This flux to bars and then we had our sitting honored Golden Matter. There you go. The first thing is regard the values Adam and the non complete. So in reality, if you want to just see how to get the value offer Valley from Supplier, the baby daughter's strings are player God get many. Do they get call? That's when it's going to give you the actual value off Adam. There you go when you make the get calls dots when we get the Adam as a response. But doctors completely taken care behind the scenes by their from supplements. So now let's go ahead and explore one more with it called Arrangement that which is part of the flux. So range is going to give you, uh, range of elements like you have to pause the starting and ending reach. It's going to give you the range of elements, since the range supports multiple elements. Ultimately, we have to use flocks because Fox is a reactive type which is far zero to n elements get best, and then we're gonna pass public y it flux, using greens, saying here we're gonna create a flux using the range right, so blocks dot range you posit starting value and undoing value. So the flux is gonna start from one and end with fight. So what is the type that it is going to return? If you go to arrangement that you will know the flocks is going to return our type off in teacher. So we're going to create the flux off type and feature, and then we're gonna give it a name, Right? Said this is the interior flux. So this indeed Aflac's is going to give the value starting from one to fight all the elements that are represented in the range, which is the start and count. It's inclusive starting from one and then emit five elements from that. That's the meaning offered. Now what we're going to do, we're going toe called the create method and posits flux. And then we're going toe. Expect next. What is that we're going to expect? So we're going to expect the elements starting from one, 234 and fight. So these are the five elements that we expect now. The next step is we're gonna call the very fate complete. That's the call which is going toe have the flux to start emitting the values toe this separate fire. No, that's going on this one. We're expecting a green signal. If you get a green signal, then we're good. Terry, go. We got the green signal. And if you want to know, like, what happens being the scenes, who again we can just call the log matter. This matter is going to give you all the elements. It's gonna print all the elements in the council. Right? So we have seen any examples of this. There you go. We got element as 12345 Forward with that, we got the un complete meant it. So we have explored many of the factory matters that are part of the flux and model. Still, there are many more methods. It is really impossible to cover all the fact LTD's. I just covered whatever methods that mere later, this course, you are happy to explore all the methods from the Flux and Mona reference documentation and the flux home page, links of which I shared in the initial part of the course. But this we came to the end of this tutorial. Thank you for watching 15. Filtering a Reactive Stream: Hi. Everyone will come back to this tutorial in this tutorial loan aboard. How to do filtering operation using Project Reactor. Now I'm gonna create a class called Flux on model Filter Dust. Zoom in a bit. It's read the first this case. So what I'm going to from the previous dsk's. I'm gonna copy a few things like I'm gonna take the trouble and then put it here. There we go. No, that's right. The first Huskies at best Public wired, filtered ist. That's a name I'm gonna give. That's changes when the lower case. And then Now let's go ahead and create the flux from the list flux dot from the trouble and then bars in the names. All right, so this is gonna give us a flux. Let's give it a name, plucks off string names, flux. And then what we're going to do is we're gonna apply the filter. Operation Filter takes in a predicate. If you have very well experience working with Java eight, then what? Our core that we're going to write will make sense. You don't have to be an expert in job away. Just the basic things. How to use a predicate how to use a function how to use a matter reference index and stuff like that. No, I wanna filter whatever name that starts with Adam to be passed to the next layer. So, yes, it represents a name. And then I'm going to use the starts with method, and then I'm gonna pause the string as he and then I'm gonna just do the lock just to show you water all the evens that are being passed this up scraper. So, as soon as we create a subscription for this flux, the flux is gonna written all the values one day, one so faster is going to pause, Adam. And then it's going a pause, Anna. And then it's gonna pass, Jack, and it's gonna pass, Jenny. Right? So after this filtering, what will happen is one Lee. The names that start with is gonna pauses filled early. So one be Adam and a novel come to this layer and then reach a subscriber so Jack and Jenny will be filter out, and it won't even reach the subscriber. Now, let's go and write those step very fire dot Create for this. We're gonna pause the names, folks. Right? And then what is it we're expecting? We're expecting Adam on Anna as part of the output, not Jack and Jenny will be sent to the subscriber and then forbid that we expected. Verify complete Toby emitted from the folks. Let's go and run this one. There you go. So it just printed the Adam on Anna here because the names Jack and Jenny got filtered as part of this filter operation. There are many ways you cannot play the filter. I'm gonna just copy it and then pulled here. So filter test lent. I'm gonna name the Senate's lend. What I'm going to do is if then lend this greater than four, then pause the element of them. Subscriber. So from the names Adam, Anna, Jack and Jenny one Lee Jenny will masters condition. So after this one, regeni will be passed to the next layer. All the other names won't be passed to the subscriber. So that's renders I'm expecting, Ah, distress case to feel, and then we'll go and change it. So let's go and check water is that it is expect. Expect next. Adam failed because the actual values Jenny, because Janey's one, which is actually matching this criteria, right? Let's go and put Jenny. But I know because we cannot have a knowledge over there. Now, let's go and run this one that's going to give you a green signal. There you go. So, based on your use case, you can apply different kinds off filter operations. But this became to the end of this tutorial. Thank you for watching. 16. Transforming a Reactive Stream - map: Hi. Everyone will come back to this tutorial in this tutorial loan aboard how to transform of flux from one form to another form. If a step, we're gonna create a this glass with the name flux and model guns form, just zoom in a bit. And then let's create the first estimated God public Lloyd transform using map. So in project Reactor, there is ah, handing method called map. Using that, we can convert flocks from one form to another form. Wouldn't name this one us transform using map. There we go. Now we need the flux. Right? Let's go ahead and copied this from one ofour previous. Just so I'm gonna take a look. Good. The factory. I want to take this one. So I'm copying this from the flux and mono fact latest class back to the this one. Then I'm gonna put it here so the faster because I'm gonna create their flocks. Right? So what I'm going to do blocks off strength and then I'm gonna give it a name called names Flux. You could go. Let's import this blocks dot from Trible. I'm going to use it terrible on. Then pause the names. Okay, So now we have a flux available on the next step is we're going to use the mob matter, right? So there is a method called map method for this map method. What I'm going to do, I'm gonna Here's a lambda And what is going to do us? Your It is going toe convert the names from the lower case to upper case. I want to keep this use case really, really simple. And then I'm just gonna log it so you don't have to do it. I'm just logging it just to see in the console on then verify what's happening behind the scenes. So after the step is executed, all the names that were going to get is going to be Adam and, uh, Jack and Jenny. So basically, it performs the uppercase operation toe each element in the flux. Now let's greet the this case. I'm gonna use the state pretty fire step, very fire dot Creed. And then we were a pause. The names flocks and followed without what we're going to do. We're going to right the conditions. It's going to expect all of these rate, so I'm just gonna copy and put it here and then, But if a complete. So in order for this meant of work, we need to actually, but that other gods never Gods tell the guards. And I'm marrying all the devil courts. Know we are all set. No, what I'm going to do, I'm going to run distress case and then see what's gonna happen. So I'm expecting a green bar. Because after this uppercase operation, basically it is going toe give you the uppercase version off all these names. Terry could give me the green bar, presuming a little bit. All these elements which are actually lower keys, are confident uppercase because of this uppercase operation. That's right. One more example of similar kind. But it's gonna be a different example. What? They want us. Same with it. And then I'm gonna name this one. Excellent. So I do not want the actual name. I want the length off each and every name. So for Adam, it's gonna be four for Anna. It's gonna before for jackets gonna before. For Jenny. It's gonna be five. I just want the length. So in that case, we'll use the Lend Matilda respond of the flux. That is part of the string, actually. So when you call the land meant there, Actually, the opera is gonna be flux off type in, teacher. All right, Because that's what we will be getting all of the is start a limited. So in here, what are the values the values are going to be? 444 and fight. There you go. Let's go around on this one. Very good. So it gave you the or put us expected? No. I'm gonna use another hand emitted that we have as part of this reactive AP ice meaning the project reactor using Lent. And then I'm gonna other new method called Repeat. So I want this flux to be repeated end times. So there is a handyman that called Repeat. So for the repeat, but that you can pause, then put us one. Basically. I wanna repeat this same flux one time. If you want to repeat this 15 times, you can possible leave us fight. So I just want to show you guys there is an method available. There is, um A tender is available if you want to repeat the fox. So if you repeat what will happen the same Okay. I want to just run this and then show you what happens. And then we'll go ahead and fix the disc. Ease. So the disguise field. But he's in this. We're expecting on complete here. But it gave you the value us on next four. So because we are performing a repeat operation on the flux, So we are repeating the same flux. Toby, um, to run One more thing. There we go. So we have successfully repeated the flux again. So if you have a use case, something like this, then please go ahead and use the repeat for that functionality. Now, what I'm going to do, I'm gonna complain. The filter which we saw in the previous tutorial and then the mat matter that we just explored. So I'm going to copy this just keys and then put it here using mop filter. So what I want to do is I want a filter or the elements for each name. If the name is greater than his dot land is greater than four. Then go to the next level and then I'm gonna do ah Purkiss operation instead of length. I want to perform the uppercase operation Can you do this? I'm gonna remove the repeat from here. When you do the uppercase operation, it's not gonna be a flux off type invasion anymore. It's gonna be flux off type string. There you go. And then and they expect so, out of all the names that we have, the one Lee name, which is greater than four characters us. Jenny. So that would put that We're going to expect this. Just Jenny. Now, let's go around on this one. Very go. So we got the airport us Jenny. So we have, ah, successfully combined two operations. One is a filter operation on the map operation. So when you have many operations like this, this is called a pipeline. So this whole thing is called up by prints of yard building a pipeline and will be building more complex pipelines in the future part of the course. So for now, you need to know about the terms. Flux is a publisher, which is a millimeter. And then what? We're operations that you're trying to do those other elements which those are different kinds of operators that are combined together to former by plane. But this we came to the end of this tutorial. Thank you for watching 17. Transforming a Reactive Stream - flatMap: Hi, everyone. Welcome back to this tutorial in this tutorial, Gordon Lawn, how to convert a flux from one form to another form using the flat map method. I'm gonna use the same this class that we used in the previous tutorials, which is Fox and model transform. Pissed. I'm going to zoom in a bit and then let's greet the foster estimated for the flat map a dust public. Lloyd, on the test method is going to be glands form using flat map. There you go. So now we have the best method. Ready? Let's go ahead and create the flocks first. So I'm gonna use Lux off string, and then I'm gonna give this a name, and what I'm going to do is I'm gonna create a flux from a terrible look Stock from it. Trouble. And then I'm gonna create the list. A razor as list. I'm gonna give a list of six elements a b and then see and then d even if Okay. And yes. There you go. We have the flux off six elements. Pretty. The next step is we're going to use the flat map as part of this. This meant that right? flat map. So when do you use flat map? Flat map is a specific use case if you have to call a DB or external service for each and every element in the flux. So this flux has six elements, right? So when we subscript with this flux, it's going to send you the element one by one, like, plus, is here being sink d e N f. So for every element, if you have to make a difficult So I d be called our external service call that returns a flux in those kind of scenarios were going toe use a flat map and it has a lot of additional options will be exploring that in a bit. So after we subscribe, it's going. It's going to pause there elements from the fox one day one. Great. So I'm gonna give it a name, and then it's giving giving me the recommendation for Lambda. I'm gonna take that so and then what? We're going to do this. Each and every element will be Commodore Flock sucking. So basically, yes is going to be a flux off another element. So I'm gonna just keep the example simple. It's gonna give you a flux off string. All right, say, if you have to compare flat map with map here, that is not the case here we are taking and put us a string. And then again returning a flux, which is nothing but a publisher. So what I'm going to do, I'm going to return a flux from it. Terrible. Okay, right. And then what I'm going to do, I'm going to creator temperament, that convert toe list. So for no assume this one has ah db call that you're making. And that call is returning your Frank's. That's what we're doing, right? Right now, we don't have the material. I'm gonna go ahead and create the method so and lead against me. The recommendation to create the method the conduct create minted this matter is going to return a list off string, because if you take a look at it here we are returning the flux from miserable right. And what I'm going to do is I'm going to make the DB or Erection service called, so I'm gonna introduce a delay off thread. Dodd sleep one second every time for each and every element from this. It terrible. That's going to be passed to the flat map. It's going to wait for a second and then what we're going to do, we're going to return irish dot us. List off the same string In addition to Dark, I'm gonna add a new value toe that or put right. So for each value for years, it's going return year and new value for beads going to return to be a new value. So if I have to put it here, if it does, he eh, we're going to get a list off the stuff year. Come on, new value. And if it's a B, it's going to be B comma. This stuff be Come on. New value so far, each and every other minutes. Going good. A new element to new elements, actually. Okay, should Now let's go ahead. And, uh, you hurts During exception. I don't want throw the exception I wanna do. We try and catch of this one. So that's good. This one surrendered with try and catch. So for each and every element, we are interesting a delay off one second on. Then it's called the next layer. Right? This is good. And then what? I'm going to Dio for the purpose off readability. What happens behind the scenes? A pretty sub scrape. I'm gonna introduce a long story. Go to know, Let's go ahead and create the step. Very fire, right step Pay for your dot create and then passenger getting string flux are it's going okay, it's named as names. That's not okay. Lets go and rainy in this one. Click on the Sri Factor Rename String bucks. There you go. And what is it? We expect himself or no, I'm going to do expect next Gohn off 12. So for each and every element, we're going to get two elements, right? So that's the reason why I'm doing a expect next count off the wall and then the next thing is very fine complete. There you go. Now that's going on around this example here on this example, it's going to give me a green bar. But one interesting thing which I would like to show you, is how long does it take in order for this whole operation to complete? So the whole operation started 21 it completed a 27. So that is working is expected because for every element and the flux. We are interesting. A delay of one second. That's the reason why it takes toward love. Call told love. Six seconds, right? That's good. No, I have some additional use cases I want. Do badly make these call, actually, So I want to make this process to perform faster. How do we do it? Let's Ah, copy this this case and then put it here from copping this whole test case and put it below the convert A list mentor. There you go. I'm gonna rename this man us using. Okay, So we're going to virally process each and every element so that it is not going to evade for six seconds to complete the whole operation. The faster bus. Let me comment. Let me remove these things and then add new things. So this is going to give me a list off. So the flocks off string, right? And after this, what I'm going to do us, I'm going to column at that called window. That's part of the flux. Creepy itself and window. You can pass some numbers. I'm gonna pass two elements. So what? It is going to do us instead of passing the element one way, one toe the flak up. It's going to wait for two elements, and this is going to be a of flux off flocks off strength. Okay, so now we have ah, for each and every string. It's gonna bait. And then once it reaches the count off to for in this example, it's gonna Vaid until nbr past in beer bust. And then it's going to go to the next layer. Likewise, it's going to wait and then is gonna wait for C and D followed by that. It's going to wait for enough. So it's going to pause elements us of flux off strength, right? So it's gonna be a flock soft, lots of string. And then it's got to the So I'm gonna remove this. It's going to order the flat map, right? No, what we will do. I just keep a bracket here. So, for flux, we're gonna use a map material right in the map, omitted what we're going to do. We're gonna make the call to the converter list. Metal this colon Colon said if we take a look a it gives you the recommendation to call that right and followed by that, there is a handy method called sub scrape on. We go subscribe on. And then this matter is the one which is going toe change a thread from 1 to 230. So there is operation called parlor. If you make a call to dark, it's going toe. Make sure the whole execution happens in parallel. All right, so what is all part of this? When the open up, this one is going to be a flux off? Let's give a common here. It's going to a flux off list off strength. Right? And what do we want? We've warned. So we don't need these curly braces. I'm going to remove that what we want. We want this operation to posit flocks of this stuff. Flocks of string to the next layer trade. So for that purpose, we're gonna use flat map. Let's take a look at what is it giving the competition issue? No, I believe I'm missing one brackets here. There you go. No, I'm gonna move this coming, and then we do not need this rate. Will not eat that. And then here, let's make sure we have the braces completed correctly. This one is there? Here? Do we have anything extra? I don't think so. Right. Flat mob. And then we're going to go convert this to flux dot from the troubles? Yes. Okay. And this is going to give you a flux off strength through this? No, let's go ahead and renders and then see how fast this process is going to take. So let's recap on what we did fasting us we are doing of Indo operation which is going toe . Wait until two elements and then that's going to be passed to the next layer. This is where this is the heart off parallel operations of year. We are using the subscript on, which is going to switch the third from one tree to another threat. And this battle operation is going to make sure each and every operation will be handled partly. And then here we are converting Doctor, were flocks off the stuff string again. So this is basically flocks off string and then we're going toe past Dr the next layer. I'm going to run this and then show you how long this operation is going. Toe pick. There you go. If you take a look at it. It started 24 it completed a 26. So it did not take a six seconds, right? Let me zoom in a bit. And then each and every element er's sent to the flux as a individual element, right? And one more interesting thing, us. If you didn't look at it until this until the request called until the subscriber made the car tow flux Raymond elements. It was running and maintained. And then, if you take a look a parallel three and parallel to so it totally switched the contacts from the main threat to the pad alter. I'll run the previous test case, and then I'll show you the difference between them. Good on this. So the whole execution started the main threat and completed a Dementor. That's not the case with distress case. Let's go ahead and turn this one. So here it started, main. After that, it's which the thread from main two parallel to one parallel one. So how many threats can we have? An emission? We will talk about that and the future part of the course. I'll show you how many threads that this project reactor it realizes in your machine, right? And one more interesting thing. If you notice the flux starts at the NB. But if you take a look at the output, we have C E. So suppose let's say you have a use keys. You don't want this order to be changed in those kind of scenarios. There are handy matters that are available with Lex for that now. So I'm going to many ways this. We'll copy the same but that and put it here. So in the place of those using paddle So I'm gonna name this on us. Parlow, Maintain order. I want to maintain the order rate in those kind off scenarios. We have two options. Oneness, concoct, mop. So can cut. Map is something which does the same operation as a flat MMA. But it maintains order. I'll go ahead and run this and then I would feel you. What happens? So here it switch from this tower to another third. Basically, it is running the whole execution or different threat. But one problem here is that it started 47 then it ended 53 again. We came back to the old straight. It is taking six seconds, right we don't want that option, actually. So in those kind of scenarios, there is a handy method called. So I'm going to copy it and then put it here. Let's come on, this one. So I'm gonna come in this and we have omitted call flat map, second ship. So if you use this operation, then it's going to be faster, and it's going to meet in the order ALS It's going and run this one. There you go. So it's which from main thread toe the paddle one thread. But if you take a look at the time, it just took two seconds. So flatten up sequences a handed mattered If you want to maintain the order and still you want execution, Toby executed parley in your application. So these are the different options we explored aboard flatten out sequence will concoct map and flat map. So the heart off the whole parallel operation is performing this subscript on on the parameter that we pause this pattern. So this is one of the key thing to keep in your mind. So for each and every input, if you have to make a DB call, then flat map is option If you want to paralyze the operation, then you will use ah factor of sequin shill or can cut map. But one thing to keep in your mind such rayborn is key. So that this became for the end of this tutorial. Thank you for watching. 18. Combinning Reactive Stream: Hi. Everyone will come back to the sectorial in this tutorial Corden loan. How to combine more than one publisher, which is a flux or mono into one publisher, which is a flux. Are mono using different operators that are available in Project Reactor. Now, let's go ahead and create the test class. First, I'm gonna name this one asked flux and mono combined dust. Okay, Okay. You cannot create a file. So it is saying the file already exist. I believe I created that already in the regard. I have it here, but some in a month. There you go. And then what I'm going to do is I'm going toe create the first estimated. So I'm gonna name this one US public lied combine using merge. So this is the actual material, right? There's actual estimated. Let's go ahead and create the flux. The first thing is, I'm going to create a flux off string. So I'm using string as an example in our to keep things simple. If you want to explore some other type or will come to do that. So I'm gonna give it a name called Flocks one, which is he called toe Flux. dot Just I'm gonna pass three elements year. Come on, Be. Come on. See? So we have, ah, flux off three elements. That's great. Another flux off three elements which is going to be flux off. Do the name is good elements are going to be d e enough. So now we have two different flux is in reality, You might be making two different d because are two different external service calls. And then you want to combine this flux to one and then returned that toe the color, right? This is a value excuse. It can happen in the applications that we are going to build in the future. So what I'm going to do is I'm gonna create Aflac's and give it a name called Merced Flocks and Flux has 100 emitted called march. You just have to boss flux one come up Flux to Oh, well, been here, Flux toe. Terry. Go. So now we have merge flocks, which is a combination of both of these elements. And then we have a name here. Now that's going on right? That this case, which is going to be stepped very fire dot greed and then pause the march flocks inside and we're going to expect next. And then we're gonna bars all these elements here and followed by a daughter is going to be D E f right. Copied us and then put it here. And we were a very fake complete. I'm going to introduce another new assert here, which is nothing but expect subscription. There is, ah, subscription also because that's the first thing that happens, right? When you make a call when you subscribe, it's going toe make called the flux on. Then from there were one of this year's subscription. That's the first treatment. So I'm violating Dart, and then we are expecting all the elements. And then we're expecting the very for a complete right. So that's going on during this one. There we go. We have successfully consider that this case. I want to just log and see what happens behind the scenes because I want to make sure all these six elements are flowing to the Step three fire. Terry, go. So if you take a look at it, I'm gonna zoom in a bit. It combined all the elements meaning three elements off from flocks one and three elements from flocks to which is being created as a Marge Flux. That's what we are subscribing to. There we go. So one interesting thing, if you notice even though you are just subscribing to this march flocks it eventually made the call to flaxen and Fox two and then all the elements started toe flow, right. What I'm going to do is I'm gonna introduce some kind of delay for each and every element to come out off flux in flux to and then see what the behaviors. So I'm gonna do a test public Lloyd combined using merch up. I mean, instead of racing, therefore aerating the brand new this case, I'm gonna just copy this and then put it here. It's a just changing off this myth. It were named. This one s a bit delay. So Flux has a handyman that call billy elements I'm. Then it digs enough object call duration off seconds one. So what does Darcis? Every element is going to be delayed by one second and then it will be admitted to the next layer. I'm gonna do the same thing for this one Duration is ah, class that got into the usual spot off Java eight. And this is part of the job or dot time package. If we take a look at it, this class is available starting from Java, right? And I know what I'm going to lose. I'm going to go ahead and run this Russkies and then see what happens. So this case field, why did it fail? It's going and take a look at it. Expected values be, but the actual values d So here we're expecting B. But the actual value that we received is D. What's going on? That's, um instead of the actual values I'm going to do, expect next count a call to see Let's go and check what happened. So the first element is year and next element is D. The next element is B and next element of C and the next element to see your next element of CF. So after the first element is emitted here right, it doesnt lead Until this whole flocks one is completed, it's going to go ahead and then start consuming the elements from the next flux. So this is called of flux off flux that is being emitted in an intern believed sequence. So basically, this fuck's the flux. Who doesn't wait until all the elements from flux illness emitted? So that's something that you have tow keep in your mind. Okay, So a lot of again, I I'm not sure whether it's going to omit the values in the same order. If you take a look at it right now, it's d on A and E and B, let's run it again and then check if you take a look at it Now it is Indy. So if you're using march in order, more toe different rocks is you have to keep in your mind. It's going not going to give you the elements in the order that you expect. For that there is another method. Call Koncak, which is again an alternative for merging the Fluxus. So what I'm going to do, I'm going to copy this and then put it here. That's me, Mr. So that the court will be clear. So combine using can cap I'm gonna give I got. And then in the place of merge, we're gonna use Koncak here. We do not have any delay or something. If you don't know that this case is gonna work as expected. Perfect, right? No. I'm going to copy this this case and then create another one here. What we're going to do, we're gonna introduce the dealing, and then check what's going on. So in here dot delay elements and then I'm going to is a duration class dart off seconds. So I'm gonna have a dealing off one second. Okay, lets copy it from here and let's go under on this one show. Take a look at that. It is going to take more time, but the order is maintained. So it started. The operation started at 36 then it got completed at 42 right? So it maintains the order also. So what happens is that what can cat? It's not going to go ahead and substrate for the flux to until the flagstone is completed. The flux to is going to start admitting the values to this gun, Captain. It'd after the flux one is completed. So here the timing wise, it started 51 then it ended up 57. Right. Let's go in the render combined, using Marge with Billy if you take a look at it, it started 1600 guard completed 19 inches, so it exhibits the execution and particle part. It doesn't maintain the order because of fracture does invade until the flagstone is completed. So this is something these are the options that we have. But based on your applications use case, you can choose which operator you want to use for your use case. Now there is another hand emitted called zip that's called and explore 0.12 Zip is again a different kind of a off merging. So I'm gonna just copy this and put it here, or I'm going to use this complainers. Incan captivated. So it's gonna be combined using zip. Right, So here flux dot zip. We have to Fluxus. And one more interesting thing is, it's not going to give you the flux directly. So what I'm going to do there is gonna be a toward argument for this one that is there. Do you want a detail? I'm just giving that name. So which is it? A presentation off flux once. First element and flagstone. Second element Say now, use case. Yeah, and the. And after that, it's going to be be under E and our father is going to be see End? Yes, right. And then what I'm going to do? I'm gonna combine this into one element by performing this operation. So we're going to return t one dark. Got to do so. Basically, it's going to return B A D B and see if so, let's take this one and then assert on this one. Let's put these in double guards. This this is one other type off merging the flux. If you have a use case like this, if you want the fast flux and second flux element to be combined and returned the art as a single flux element, then go ahead and uses use case that's got and renders. And then I'll show you the result. And there you go. If you take a look at it, it gave it. The result is a combination of the first element from frocks one and first elemental box, too, and second element from blocks one and second element from flocks to So these are the different days off merging the flocks using the project reactor. So we have explored quite a lot of examples. I would highly recommend you guys to go to the documentation. If you do not have any of the examples that I have here is not applicable for your use cases. And I'll show you are what are the different views to reach out to people if you do not know what operated they use in the last part off this section. But this we came to the end of this tutorial. Thank you for watching. 19. Handling Errors in a Reactive Stream: Hi. Everyone will come back to this tutorial in the sectorial talk about how to handle any kind off error or exception that happens in the reactor sequins for that purpose. What I'm going to do, I'm gonna create a class called Flux and model it. It just okay, zoom in a bit. Now, the next step is I'm going to write the test emitted public. Lloyd. Flux it a Handley. There we go. We have the estimated ready. I'm going on a date, this method, but our test sanitation. Excellent. Now we will create the flux, plucks off string, and then I'm gonna give it a name. Thing is, we need to import us. The name is going to be string flux and flux, Dodge. Just well past, like, three values. Okay, be and see. So we have a flux off three values. And after the three values, what I'm going to do is I'm going to can captain eight with another. So this is something which we have seen enough. The when one of the previous tutorial not concoct map concurred with. And it's going to be flux dot editor and this is going to be new or on time exception. Let's give a message Exception. How good and followed by a dark. I'm gonna have Anel Ament. This element will never get invoked because once an error occurs, that's the domination. Even off that reactive sequence flux dot Just I'm just gonna have the values D. Okay, let's go ahead and write. This case is going to be step verifier dark, create string flux. There's gonna have the log here just to see all the van's in the console. When we run this this case and we expect that expect subscription. The first thing is we're gonna expect that subset of flimflam from the flux and then we're going to expect the next which is gonna be the three evens are I can give, like, expecting next off these three events and followed with that. We're expecting it, right? Expect it. It on this error is going to be under an exception. Dark plus, and forward with that, it's gonna be very fine, right? This is something which we have quoted already. I just have this completed. I'm just gonna go ahead and run the stress case and then see whether I have a green park. So This is a way we have been discussing on how to handle any kind of hitters, right? Basically, this is not a handle. This is a way we can check whether an error occurred or not in the reactor sickens. So the first approach that we're going toe use in order to handle any kind of area and the reactor sequins is that it doesn't matter. Called on area resume said it did not something which will take a look at it on a resume. So whenever there is an error, this particular block will be involved and then accesses. It gets the access to the exception, okay. And followed without what we're going to do. We're just going to print the exception, Foster, because we want to know what exception happened, right? It is. It is a good practice to from the exception exception s and followed with that, we're going to print the exception. There you go. And what we're going to do is on every resume is going to return. Uh, Flux, basically on error. Go head and returned this flux, right? Not written. Go ahead and resume the sequence with this flux. What? I'm going to do I'm gonna But don't flocks dot Just so I'm just gonna return a default value. Do you fall? Let me add one more d. Ford one. So whenever there is an error, this block will be executed on a resume. Block will be executed, this blocks gets executed, and this is going to return the flux. Now, what I'm going to do, I'm go ahead. I'm gonna go ahead and run the stress keys and then see what happens to this this case so that this case failed. Why did it feel zoom in a bit? We are expecting the exception us this class, which is the runtime exception. But we are receiving a our next of default because on exception, this particular blocks gets executed, and this particular block returns the flux off this. So we're going to change that this case. So I'm gonna come on these two lines, and then I'm gonna put expect next in the next. I'm gonna boss this, and it's going to be very fine. Complete. Okay, Now, let's go ahead in this this case, Well, this has been done so after the other, we're going in this flux, and we're asserting on that. Frocks, go ahead and run this Russkies. Very cool. So it is successfully. So here we are, just logging this exception, which is this particular line, and then be returning the flux. So on any kind of together and this reactor seconds flow, it's going to exhibit the on error racing block. So this is one of the approach off handling exception. Now, let's take a look at the another approach. So the another approaches with a copy of this and put them in that year. Flux handling. I'm gonna name this one us. On it is we've done right. So instead of this, remove this court, it's going to be on it. It There you go. And you have to provide Ah, fall, doc. Fallback value. Actually, the fallback value here is going to be default. So instead, off, if you have to compare this example of the previous one in the previous one be returned off Fox on the error handling in here, that's not the case. We just return a value which is a fallback value on any kind of error. So in that case, we have to remove this and then after close this here. So it is just going to turn you one value it instead of the whole flocks and the error resume that's going and run distress case. But on the dis case, there we go after this. See, we are receiving the default because after the sea, we have a one time exception and the runtime exception exhibits 100 and block and that on air it and block is going to return you the default value to complete this reactor sequence . Now, this is one of the person we talked about on a resume on on error written. Let's take a look at the other approach, which is the map perimeter. So there is on aerial map. Let's go and explore dark. So I'm gonna name this one, us on it, it right saying here what we're going to do, we're gonna have the same thing, but in the place off on a return we're gonna have on other mop. So, in the on editor map, what we can do is we can are saying exception from one type to another type. So here we're running around. Time exception, right? Okay, let's go ahead and access that exception using land. Uh, it gives the access to that exception. And after that, we're going toe use new custom exception. Custom exception. Basically, this exception exception is not there at what I'm going to do. I'm going toe passing this exception. That's good and create this. So I'm gonna use the option return. It's going to give you the option to create this exception, and then I'm gonna create it in this flux on model, they grown package itself. Look on this one. And then it would have, um, let me zoom in a bit. So I'm gonna create private string message, this document surgical dough you got, get message. There we go. And I'm going to generate the gators and centers for this misjudgment. That message variable, actually, there you go. So now you have successfully created the custom exception in the plaques and mano a grown package. Let's go back to the class. There we go. Said this approach is like our signing exception from one type to a custom exception that you have in your application. So in here, what happens in the place off except next? Expect next. You're gonna have custom exception dot Plus, there we go and this is going give ex expect error. There you go. And we cannot have very, very complete. In that case, it's going to be just fine. There we go. That's going on under stress case. Okay, so we got the green signal. So this is one of the other approach off handling the exception in a reactor sequence, using the step using, though, on other matters. Now let's go ahead. And an ANZUS use case. It's a shoe we want entered is a retrying. So whenever there is an exception, I do not want toe, just go ahead and catcher and handle it. I want to perform a re Troy to make sure the following retry operation may be successful in those kind of scenarios. It's very, very simple to do that, but retry and in here we are ascending this rate. Let's say for each and every value are making our deliveries call on the database call of you might get an intermittent out age issue, and if you re dried, then it's gonna work, right? So in those kind of scenarios, we want a performer retry before we and this flocks with an error. So there is often called retry and then begin pass a value to that retrain committed. What that is going to do is it is going to perform the retry two times. Let's go ahead and run this and then see what happens. So I'm gonna run this. Okay, now we got an edit and the exception the editors, we are expecting the custom exception here. That's what we're expecting. Body particular. Good. We got the value as on next off year, the reason being they're performing a retrial rate. The same sequence is going to be emitted two times. And then we're going to get the custom exception. Lets go and run this one. There you go. So we got the green signal. If you take all over the floor. Stevens fast, ABC. That's the regular sequence and followed without e b C. That is the first retry and forward without another ABC. It there is second retry. So let's say you have a use kids for the first or second retry, you're gonna just ignore this in those kind of scenarios. People not throw this exception and the baby handler will be totally different, meaning they expect into the place of Expect better. We will be having the very fake complete before we want to the next day, estimated. Let's go ahead and run that and then check with the This case is pausing or not. So it is not. Basically we are performing retried two times, and if you take a look at the evens, the evens are emitted. ABC is emitted two times, right? So in those kind of scenarios, we need to have ABC two times a year in the district verifier. Otherwise, it's gonna feel it's got around this. There we go. We got the green bar, the reason why we got the green bars because we have ABC, ABC and NBC. So ABC is getting emitted three times. One is the original flow. That is, this one on extra is a fast retry, and next one is a secondary try. Now that stock aboard under use keys where you want to perform a kind of back off before you perform a retry right? So in those kind of scenarios, there is an option available in the flux AP itself morning that named this one us reactive . Back off. So in here, the place of retry we're gonna use Retry. Back off and you will provide a duration here. Duration. Dart off seconds and fight. So I want to perform a five second back off before I perform early. Try. That's what I'm instructing. The flux should do, Actually, let's go ahead and run this one. So the first is a first called the original call. And then it's gonna wait for like, five seconds are approximately five seconds here, if you take a look. A The second rate happened at 22nd which is 15 plus 20 seconds like seven. And then the next retry happened at 29. So this is where the back off is very handy. So you want to perform a back off before you perform a retry right? Send one more interesting thing as artists keys feel the reason being, we are expecting a custom exception, right? But the actual exception that regard us illegal state exception the reason being for take a look at the message that he tries exhausted. So in that case, we have toe put this illegal street exception here. Let's go ahead and run that this case that's good for approximately five seconds. So that's one of the thing with Project reactor. It is not. If you have any time sensitive, retry then even though you provide the value as FISA can't, it's not going to exactly return the 5th 2nd it's going to be. Plus, our miners were not so seconds. You always have to keep that in your mind. But this we came to the end of this tutorial. Thank you for watching. 20. Infinite Reactive Stream: Hi. Everyone will come back to the sectorial in this tutorial will go ahead and called how the flux and mono interacts with time for this purpose. What I'm going to do, I'm going to create a class called Flux and mono. But time just zoom in a bit. Now let's create our fussed this case. But just and I'm gonna name this one as public wide and find it secrets. So you're going to read off flux That's going to generate and infinite sequence. How do we do that? The very daughters, by using flux, has a handy method. Call in double for this interval meant that we have to posit duration. Duration is a class They got introduced as part of Java eight, and that is part of the Joe our time package. So I'm going to use the duration off milliseconds, and then I want to mention the value as 200. So for every 200 milliseconds, it's going to generate a value that value is nothing but a long value. It's going to start from zero, and then it's going toe. Keep emitting the values basically, and in five seconds, not value off again. It's gonna keep emitting the value. So we need to stop. At some point, we will explore the different techniques off how to stop the sequence out to stop an infinite sequence in a bit for no, let's go and give it a name. It's going to limit of flux off long. And then I'm gonna name this one us and find it books. So we have the in Fine it flux. Ready Now I'm going for the sake of the readability purpose. I want to print the values that this going toe amid the flux this flats is going. Emmett, As a bonus, we add a subscriber toward this particular test minute. I'm going. I'm not going to use. Ah, step Very fire will do that in the next test case. For now, I want to show the behavior how, As soon as we add the subscriber how it is going to start emitting the elements, so in fine influx dot Subscribe, not subscript on. Subscribe. And then I'm gonna name the soonest element, and then I'm gonna just print the value in here levers and less element. There you go. So here we have attached to subscribe, right? Let's go and run this and then check what happened. So we are expecting the in finite sequence to start and then keep emitting the values I'm going. I'm gonna go ahead and run this this case so it on the disc ease. But nothing happened after that. So we have, ah, request unbounded call from the subscriber to the flux. But the method guard terminated because the method guard completed. So this is one of the behavior offer non blocking court. So basically, as soon as we're under this case, this language executed, and then this lane got executed, right? So after the slain good executive, since it it is a sinkers and non blocking by its nature, it just came out of the block. So what? I'm going to reverse in our to show you this behavior in season currents and non blocking. I'm going to add a thread dot Sleep off three seconds. Okay. That side this when under stress case. Basically, this method is not going to get completed, and it is going to just wait until three seconds and then it's gonna come. All of the metal execution. Tirico, if you take a look at it So we got the even starting from one. For every to milliseconds, we have the elements admitted and then But then three seconds. It emitted like 40 elements. If I increase the value toe 6000 it's kind of 6000. Basically, we wouldn't have this method stop for six seconds. What I'm going to do is I'm gonna reduce the value 200 milliseconds. I'm gonna run this so African on the this case so earlier. It emitted the values until 14 but right now, but limited the value until 29. Right? So this is one of the way we can create an infinite sequence. And this is one of the behavior off reactive programming, basically asynchronous and non blocking on. One more thing. If you notice the actual matter, exigent started it. Main mattered after the request solvent the whole execution off evens from this in front infi influx, it started execute, but a different threat, which is spotted one. That's the reason why after we ran that this case, this just cases running in the main TERT. But the actual emission off elements from the flux is happening at parlor one. That's the reason why we have limited court executed, but none of the elements they're printing in the council. So now this is not a test case, right? Let's go ahead and write. The disk is how to be right in this case for an infinite seconds. We cannot use their door sleep, right? That's not the right way to do it. So I'm gonna create a testament it on fire. Sequins. Just Soviet. Missing a colleague. Gracious. Did he go? No. I'm going to use the same thing. Bring it here. So flux as a method call. Take right. So it takes in a value on it is just going to emit that much of value. So I'm gonna positive values. Three If it passes, the value is three. So for writing the Jane, it excuses. We always use the reactor tests library, which has a step very fire class. Right, Stephanie, for your dark create, and then what we're going to do, we're gonna So this is not a in finance flux anymore. It's a fine it flux. And then we positive finding flux as an input. And then what is the next step? The next step is we are expecting the subscription And after that, we're going to expect the long value rates of you're going to expect next us zero ill followed by that one ill and do it. There you go. So it's going toe Emmett. Three elements and then it's going toe come or of the fine it folks, and we're going to get the complete human very fair complete. So this is one of the behavior off strip, very fire. So very for completeness, like a subscribe call which is equal to this one. And then it's going to wait until all these humans are published from the flux. So if you have to comfort this toe imperative programming. So in the case of imperative programming, this block off court doesn't go toe goto this block until this execution is completed. That's not the case here. Here. We're just creating the flux. But the actual flew off even happens after the live. After this step referred, that create call is completed. So that is something which we have toe. Keep it not mind, right? No, what we will do us. We will use a map mattered. And this sequence so sequence, I'm gonna name this one US map So the mad mother is going to convert from one form to another form, right? That's the way we have seen things. So that uses a magnet that and getting go long that long. We're going to convert Doctor Interior So new in de gier l dot into value. So this is going to be a flux off into. Basically, we're trying to perform some kind of transformation. After the flux start emitting the values in the place of zero l. We have to replace that with 01 and two. There we go. I'm just writing the stress case. Just toe perform some kind of operation on the in. Fine it sequence. Meaning the finance segments that is being emitted from this flux. There you go. No, what I'm going to do, I'm going to introduce some kind of delay after each and every element is emitted from this flux. Someone named this one us but delay. And in here that delay there is a method called Bill elements. We have seen an example of this already. So I'm going give duration dot off seconds. So even though this in travelers emitted every 100 milliseconds, I'm delaying each and every element by a second. And then I am asserting on it. Let's go to London, us. So here, if you take a look at the time off the previous day's case, everything got exhibited between 15 and 16 2nd rate. Basically everything happened. All these three evens, but imitated within a second. No, I'm introducing a delay off one second, so it's going to take more than a second. So if you take a look at it 1920 21. So every second we received and even and then we received their own complete human. So why are we doing this? Diarrhea is to perform some kind of operation on the flux that is getting emitted on the values that are getting emitted by the flux. Start intra limited. Basically, I'm making raise comfortable to ride cord and performing some kind off a map operation and daily operation on a sequence that gets emitted using the flocks are implemented, so we have explored like 4 to 5 examples. That's good. I would I recommend you guys to explore more examples, and if you have any doubts or questions, please raise a question. Our cinema to me. What does the came to the end of this tutorial. Thank you for watching 21. Back Pressure - How it works ?: Hi, everyone. Welcome back to this tutorial In this tutorial will core and explore how to apply back pressure on data streams that are emitted by the publisher. Before we get into the courting part, let me highlight Waters back pressure. What are the benefits that comes with back pressure? Let's revisit the reactor little flow off the reader streams and project Reactor. I have the publisher in this example as a database on our subscribers. Nothing but the application. So the first call that we make to the databases get all items meaning Give me all the items that are matching this query. By now we all know project reactors asynchronous and non blocking. So after the call is made, we're going to get a reference for the flux and using the Flex people attach a subscriber and then call the subscribe Minted. After we make the call to the subscribe Minted, we're going to receive a subscription from the publisher, and after that we're going to call the request method. They responded the subscription and we will pause. The value is unbounded. Normally we don't make this call explicitly. It happens by default. And after that, the publisher is going toe Emmett, All the items one by one until it has no more reader. Once it reaches the data limit, the next thing is we're going to receive the incomplete. Even so, this is the default flew off Project Reactor. All the examples that we have seen until now, in Argie unities cases, we have explored just this flow. Now let's talk about back pressure. Back pressure is a technique through which the subscriber gets a control of data flow from the publisher. Let's take a look at this using a example if you take a look at this example, the 1st 3 steps are the same for knowledge assumed to get all items is going to return. Your flocks often items, but as a subscriber you do not need all the 10 items. In that case. The 1st 3 steps, like get all items the subscribe to the flocks and subscription that gets written from the publisher are all the same. The next purpose to take a look. Attard answered off the request minted calling with on Boehner data here we're making the call that just one meaning we are requesting the publisher tojust publish one item do not send me all the items that are matching this particular query research. Just send me one item and followed by that, we're making another call called The Cost One. Just send me the next item. And after that, we're making the cancel call. So even though the Squidgy returns like 10 items here we are just getting items. So this way you get a lot of control. When you say it, the subscriber gets a lot of control on how the data assured flow from the publisher. Now, let's go ahead and explore the same concept using the court. It's got to the intelligence the faster because we're going to create the this case. But this case name is going to be flux and model back for sure. Just going to zoom in. So I'm going to create a dirt s case. I just public Lyon back pressure Tous That's a name I'm going to give for this dis case back pressure just and followed by that, What I'm going to create is a fox. That's a fasting, right? I'm gonna give flux dot range. I'm gonna use arrangement that I'm going to give the rain just one commodity. So this is going toe Emmett off flocks off 10 items, right? And followed by that. What we're going to do, we're going toe, give a police order, Give it a name for this one in De Gier. So I'm going to name this one us fine influx and what we're going to do. We're going to create that this case using the Step three fire. I'm going to write script, very fire dot create and positive. Looks fine. It flux. And after that, what is the first step that we're going to expect? We're going to expect the subscription, right? That's a question. What is an extra? The next step is I'm gonna request. So even though it's going to omit all the items, I'm gonna stop the default behavior and I wonder subscriber to take control the subscriber Here is a strip Very fire. Hey, then send me one of the one element And what are we expecting? So they expect netters next is going to return one body great and followed with that we're going to do then request Send me another item. So here it should be expect next. Expect next. So then request one more item and followed by that Do they expect next and then do canceled ? I'm gonna council, then cancel. So after to the council, the one leading us you're going to be you'll be able to do is just very fine. So because you cannot a very fake complete because after the council is emitted from the subscriber, there is no way any event is going to flow from the sub scraper. Let's go ahead and run this one. Okay, we got an editor. Let's take a look at the other. So we received. Okay, so here they should be to basically, that's the reason why we got the other Take a look. A the editor message Expect next is one expected value is one, but the actual values took. Let's go ahead and run this example. There we go. We got done. Green bar. Let's explore the evens that are being logged here. The faster pace. Answer, scribe In after dark, we made the request. One call. This is to instruct the flocks to Emma just one element. And after that, we requested for the next element. That's the reason why you see on next first even value this one. The next even value is two and four with a remainder cancel call. So these are the flow off evens where the subscriber takes control. How the data should flow from this flux, which is a publisher. So we wrote the desk case right now, let's programmatically implement How can we do that using, uh, valid subscriber. So here, step very very is reacting. Meaning not reacting. Acting as a subscriber. Let's attach a subscribe mentor and then check How can we implement it, actually, so I'm gonna create our test minted. I'm gonna name this a nice public wired back pressure. So that is not going to this case. I'm just creating a janitor's case, But this is not going toe assert anything. I'm going to show you the techniques. How can we programmatically achieve it? So I'm gonna use the same example here, and what we're going to do is we're going to Here's a fine it flux and attach a subscriber , which is a subscribe minted when you are tighter subscribed. That's when the data is going to flu. So in the this case, the step very fairest acting liquor subscript call, actually. And the first thing is we're going to get the element right element a shot and then you're going toe. Have the logger us element. There's I'm going to log element here and the next argument What is the next argument on extra argument is the exception handling. So when we get exception, is he out of any type it you get doc sister the exception. And then I'm gonna name this one US exception this plus me and forward without the next thing this subscription meaning the uncompleted but not the subscription. It so told one. If the whole floor is complete, then this block will be executive. It's out, and this is going to be just the longer I'm just logging it has done. And this is very good access to the subscription. Actually, so subscription give the name of subscription and this subscription is going to request sub doctor request. So this is one of the approach off programmatically taking control of how the reader should flow from the publisher. So this is a publisher here. The substrate meant that takes in four arguments as an input of the fashion is the actual element. The 2nd 1 is the error handling, and 3rd 1 is the completion even, and the 14 is actual subscription. So here we are requesting for two elements. Let's go ahead and run this. You will see just two elements in the lager, and after that you will see it done printer over there. So if you take a look at it or even not even done because done gets executed only if there is an on completely different. When there is a council, even there is nothing like that will be emitted. But in here, there's no cancel. Also read the reason being you're just requesting for developments. After the two elements are emitted from the flux, it's done. The flux is done with its job. No, let's go ahead and explore the cancel minted so back for sure underscore canceled. And in the place of request, we're going to call the cancel Minted. If you remember from the our previous lights, meaning during the initial part of this course, we talked about each and every interface, right? The subscription is interface, which has the requested counsel, So using the art, you can control the data flow. If we do a cancel, what will happen this. Nothing will be printed in the council. So if we take a look at it after Don Subscript were immediately making the call to don't cancel, let's run the previous example and then we will check the difference, actually. So if you take a look at the first Collis under questo Hey, just sent two elements. Where is that called going from? That call is going from the subscription Dr Quest matter. Now, this is one way off handling it. But this approach doesn't give you much control because you can aid there Newquist or cancer. Now, that's take a look at the technique off how to customise this? How toe Have more control on the arena floor. So I'm gonna copy this smith it and then put it here. And then I'm gonna name this one us customized back for sure. So let's name this one US customized back pressure. Okay, let me minimize this window. So that so that the court will be clear. Okay, so now what we're going to do is the first thing is, we need the flux, right? No, You're going to call the subscribe omitted, but in the substrate minted what? We're going to do is we're going toe use a class called based subscriber that this part of the project reactor it's a new base subscriber. So there's an interface very have to implement it on its own. What I'm going to do is, um I'm going to do our data level validation. If the values does, then go ahead and cancel it. That's what I'm going to do. In order to achieve that, What we have to do is we have to implement the hook on next month. This isn't one agreement that you need to have if you're performing your data level tradition. So if the value is for I'm going to cancel the starts, that check which I'm going to do, So what I'm going to be The first step is I'm gonna request for values one by one. This is like you're calling the subscription dot request. And after that, I'm just going to print the value value value. You see this this and the next thing this if the value equal equal before a little before, then cancel it. That's what I'm gonna do, right? Let's go and run this one. So this is ah, one way off taking more control from the subscriber, how the data should flow from the subscriber. So what we're doing here is after the search parameters called and hook on. Next is going records for the elements one by one and after dart. If the value reaches four, then we're calling canceled. Even so, we're instructing the flux not to emit any values. I'm done with the subscription. I'm going to run this as soon as the runners, if you take a look at it. The fast caller's request, unbounded by default, that happens. And after that, you take the control. Hey, request one a. Just send me only one value. And after that we make the request. One call we received the on next even does, too. And then we make another call with one elements. The request call is about Give me one moment. The value received is the actual element that is received from the frocks. So when the value reaches for then we are calling the cancel cancel just part of the subscription. And then the flux stops emitting the value from the flux from the which is a publisher. So here it is supposed to Emmett and Elements. But this already feature. We are just requesting for four elements and then we're cancelling the subscription. So these are the techniques off Taking control off how the data should flow from the subscriber. There are some advanced techniques which are not the scope for the scores. I'm planning to create a separate course on how to write reactive programming causing project reactor and few months. So I'll be covering Lord of Additional back pressure handling techniques in that course. But this we came to the end of this tutorial. Thank you for watching. 22. Project Reactor - Push/Pull Communication Model: Hi. Everyone will come back to this tutorial. Industry tutorial will talk about the data communication or interaction model and project reactor. This is one of this light which we discussed in the previous tutorial. That's talk about how the data flows between the subscriber and the publisher. In reality, both the subscriber and the publisher interacts actively for the whole data to flow. Just by looking at it, we can call the project reactor this push Bista communication model because the publisher is the one which emits the data to the sub scraper. But that's not true. But the example that we have seen with the back pressure the subscriber pulls the data as spirits need. Basically, the subscriber takes a complete control Subscriber pools for the leader. And based on the request, the publisher is gonna limit the data to the subscriber to summaries. This the Project reactor interaction model is both a push and pull based communication model. So but this became to the end of this tutorial. Thank you for watching 23. Hot vs Cold Reactive Streams: Hi. Everyone will come back to this tutorial in this tutorial. Will Koran loan? What is a heart reactor stream? And what is a cold reactor stream for that purpose? What I'm going to do, I'm gonna create a this glass with the name cold. And but publisher just And then the next thing which I'm going to do us, I'm gonna create out the skis. So this case is going to be a dust public lie. It, I and the matter is going to be cold, publisher. Just there we go. We have the best case ready. The next step is I'm gonna create a flux, so I'm gonna use the just emitted, which is part of the flux. Look, start just I'm gonna parson seven elements to it. A B C D E N. Yes. And then I'm gonna give it a name for this one. That's good apiece placeholder for this one. Flux off type string. I'm gonna give it a name. String flux. There we go. We have the luxury on the next purpose. I'm going toe dealing each and every element by one second. That's going to be duration dot Off sickens what? So each and every element ISS delayed by one second. So in here, what we're going to do is we're not going to use the step. Very fire toe, right? This cases here, I want to show you how to have multiple subscribers and how the dealer will flow if there are multiple subscribers. So the posting us, it's going to be string flux. God subscribe. And I want to keep this use case really, really simple. What I'm going to do is I'm just gonna print the value. So this is some Graeber one and I'm gonna print the value. There you go. It's done right. The next typists. I'm gonna give asleep off two seconds. So it takes in a millisecond as an input. So I'm passing 2000 which is equal to two seconds. I'm gonna add the exception to the method signature and the next of us. This is the difference between this particular test minted Camp Otto. All the other ones that we wrote. I'm assigning one more subscriber, right. I'm gonna name this one as subscriber toe. Okay, the next up us, I'm gonna introduce us to the EAP off four seconds. Now that's good. And run this and then see what is a behavior in the control. So it started emitting the values. It is a meeting, a value after a second, because we have a delay introduced in the flux that Zuman. And then check the result of those subscriber one. I got the value a first and then be next and subscribe to If you take a look at it, it got the value off your first. So basically, every time a new subscriber gets assigned, zoom out emits a value from beginning value from beginning. Right? So even though even though we add the second subscriber a gain in its value from the beginning. So if you have to combat this, you can compare this tour http request. So every time you make a surety request, your new history with response will be billed and then sent to the claim. It is similar to that. How will be the number off subscribers that you are every time This flux is gonna omit the values from the beginning. This is called cold publisher. All the examples that we have seen so far they are cold publisher. Now let's take a look at the heart publisher, Heart publisher is the exact opposite of the cold publisher. It is not going to omit the values from the beginning for any new subs. Strieber that gets added to the flux. What I'm going to do, I'm going to copy this and then create the next test case when I minimize this. Okay, let's name this one. US heart publisher. Just he wondered. Were not rating the Huskies per se. I'm just naming this monastic test now. What we're going to do is we're going to use the same flux that we have here for this example. Toe. So we have the flux ready? What is the next step? The next step is we're going toe called. Ah, publish Mint. That which is part of the fuck's. And if you go to this publish Minted what this is going to return. This is going to return something called the Collectible Flux. So let's copy this. I'm going back to the this case correctable flux. There's off type string. There we go. Gonna name this menace. Correctable. Looks, Let's import this corruptible folks. Still, we have the collectible flux ready on the next trippers in order to make this flux to behave as a heart publisher, we have to call collectable flux dark. Gonna, and you can are any number of subscribers after this. Okay, so what I'm going to do, I'm gonna call collectible flux dot Subscribe. And then I'm gonna keep this example simple, like here. I'm gonna copy this. There you go. It's as simple. And after this, I'm gonna give it read or sleep. Stir. Don't sleep off three seconds and followed by dark. I'm gonna have the second sub scraper. Okay, So I'm gonna name this one us? Yes. To. And there's gonna be a threat or sleep off for sickens. The reason why I give this is because totally we have are six elements, and all these elements are going to be admitted to the subscriber every one second, right? That's the reason we have the values set as three seconds and force against. Now that's go 100. Run this example and then check the results in the console. So it's gonna admit the values 11 day One if you take a look at it. Yeah, that's great for the district complete, And then I'll zoom into the result and then compare this with the previous one. The subscriber one received A and B and subscriber one received. See And if you take a look, A. This is a first entry off subscriber to in the console. It did not receive the elements from the beginning. It started to receive elements from the time it subscribed owed. So if they had to put some commons here to make sure we understand this correct does not emit the values from So this is an example of a hot publisher. Stop the girls and all those things that were good examples off hot publisher. So this is this is a difference between the heart publisher and cold publisher. You should be aware of this because you might build some use cases based on these two types off screams. But this became to the end of this tutorial. Thank you for watching 24. Virtualizing Time in Junit: Hi. Everyone will come back to this tutorial. Investigatory, A little court on loan. How toe which relies the time while running the test cases. The benefit of this one is something which I will explain during the end of this video. That's good in court. This one for this purpose. What I'm going to do, I'm gonna create a class called ritual nine dist. So we have the class ready. Is women a bit on? The first thing is, I'm gonna create a disgrace. So I'm gonna create one with order, virtual time and the other one with a virtual time. The fastest case is going to be the tower individual time. We have already quoted a similar functionality before, but still, I'm gonna highlight this using this example. So I'm gonna name this one us testing the told with jewel time. There you go. On the next thing, this I'm gonna create a flux off type long plucks off long, and then that's important. This Let's give it a name. There's gonna be long flux, which is equal to flux dot I'm gonna use the interval factory, mother. So every one second I'm gonna have and even emitted so it's gonna take the value a string. Basically, we're going to get off flux off three elements off night long. The next episode I'm gonna create those strip very, for instance, straight. Very fire dot create and long flux. So it's validated the values basically violating the evens. Expect subscription. That's a fast, even and followed by that We're going toe wait for duration off. Three seconds. I don't think that's needed. So what I'm going to do, I'm going toe. Expect the next value us zero l one ill And so these are the three evens that that you're going to get from the flux. And towards the end, it's going to be very fight complete. Let's go ahead and run this one. So that is something which we have. Cool. Already. I'll show you what I'm tryingto explain here. So the dusky started. It's going toe received the evens. Since we did not log anything, we do not see anything here. I'm gonna log it here on their done it again so that this gets doctored. And if you zoom in the result. So it started only three second and then 24. 25 26 for every second we gotten. Even so, in order for this whole disgrace to complete, it took three seconds, right? If you have, like, 10 or 20 different s cases, then think about the bill process. It's going to take 30 seconds just for these disguises. So in order to benefit this in order not to use the actual clock in the machine, we cannot actually visualize the clock. So there is an option already available, which is part of the project reactor to slavery. So I'm gonna rename this one us that virtual time. The foster is that we have a class called Virtual times Killer ritual Times killer, which is part of the reactor, Not just not scaler package. And then it has a method called get are sick. So this is a method call which is actually going to enable the virtual time. So this is going to make sure it is not going to use the clock that is running in the machine. It is going to enable the ritual clock for us on the next trip is what I'm going to do. That premium is this. I'm gonna use the same flux and in the step very for you. We're going to have another change called step Very fire Dark. It has a method called the virtual time. So if you take a look at it, we're gonna use that and it takes up. Factory mattered was just called a supplier factory function interface. And this is going toe give you the flux. So if you have experience working with function and trapezes in Java eight there is something called a PSA player. The syntax for this menace Darkman Sosa player, which doesn't take any input. But it will just supply with values. Say it could be anything but in here. We're going to supply our flocks, which your time got log and followed by that. What is that? Even we expect the subscription Toby emitted After that one leader evens are going to be emitted from the flux. So in order to make sure we made for three seconds, we're going toe, have a duration off seconds three. And after that, what do we do? We expect duh similar even 01 toe and forward without very complete, a fair under stress case. It's not going to wait for three seconds because we have virtualized their time. We're on this one. There you go. It just took one second. If we take a look at it that just started the 39th 2nd and it ended at the 39 seconds. But if you compare this one with this one, I'm going on this one and then show you that it's not going to finish it in the same second . It's going to take three seconds in order for that this case to complete. So this is one of the handy methods that you can use in your test cases in orderto save your bill time are reducible time too fast in the build process. Now let's go ahead and make this change in one of the existing excuses. What I'm going to do, I'm gonna open this. So I'm gonna open the flux and model complain test If you take a look at it, these test cases have this delay elements. So here we have this one right. What I'm going to do, I'm going to implement this change in here. So fasting that's under stress case and then see how long this risque steaks and then will implement the virtual time approach for this particular this case. So if you take a look at it, the values are getting emitted one by one. And it took the total off six seconds. Because we have six elements and each and every element is emitted with the delay off. One second what I'm going to do, I'm gonna come into this one, okay? The first step is we have toe make the call. Could've visual times killer, right? That's a fast car ritual. Times Gittler dot Get arson. There you go. So this is going to enable the ritual time for this particular this case, What is the next step? The next step is that we're going to use the step very fire dot virtual time and we're going toe. Use this supplier functional interface in tax, which doesn't take any import. This in Texas Orlando syntax, if you do not have any knowledge about Lunda, have a course on this topic, which is modern job alone travel eight features because ring it, I would highly recommend you to indulge in dark one. So here it's going to be the march flocks dot log. So we are supplying the flux. And after that, what do we expect? We expect this subscription and the key thing is you have to make this call, then await. If you do not make this call, the virtual time is not going to work. So you're going tohave The duration dot off seconds six because we have, like, six elements that the reason why I gave the duration of six seconds and followed by that what we expected we expect the next count is going to be six. Because either you can expect all the elements like here are. You can just give the conch and followed with art. It's going to be very fine complete. There you go. Now that's good. And run this Russkies for understands case. Actually, this is going to take just a second. If you take a look at it that this case is completed, it did not take six seconds like before. So there are many of these cases with a similar concept. So I would highly recommend you guys to go ahead and change this. So if you take a look at it, this is one more which is using the duration. But it did not have the virtual time concept. You can consider. This one has a homework. You can go ahead and implement this. If you're stuck up with any kind of issue, please reach out to me. I'm happy to be on, but this we came to the end of this tutorial. Don't give her watching. 25. How to get help ? : Hi. Everyone will come back to this tutorial in this tutorial. I'm going to give you some insight on how to get help with some of the specific use cases where you're not sure which operated to use in your specific use case. Trusting you can definitely retort to me. I'll help you out into tra Mining. Which operator in Project reactor to use based on areas keys the next best place to reach out us. The Project Reactor of Friends grade. So Project Reactor Reference Guide. When I click search go this fast link you go here. This documentation is the best documentation I have ever seen for any library that is out there. And if you go little bit dawn getting help. There are a couple of places. One is the letter computer community Go here There is a specific chat room, so in this chat room, you can sign in on, then ask for your questions and they will be able to help me out, and they will be able to guide you on which operator or any kind of fell Guerrier toe project reactor. They'll be able to help you. The next thing this for scrawl it down. There is a section which operated way need. So this is under the best place to reach out and then find out which operator do you need to use in project reactor for your specific this case? So these are the three different pri