Hi, everyone.
Welcome back.
In this lecture, we will learn about the technique to connect to a streaming endpoint using web client.
So for that purpose, we'll be working on the movie service because movie service is kind of a service
which is a client for the movies info service and the movies review service.
So right now we have a streaming endpoint that's built in the movies info service.
And what we are going to build is that we are connect to that streaming endpoint using web client,
okay?
Because right now, if you take a look at our movies controller, the movies controller connects to
the movies info rest client and reviews rest client.
And if you take a look at these endpoints, these endpoints are basically you make a call, which means
you make a request and receive a response in a non-blocking fashion, and then you close the connection.
But in here we are going to build a streaming client that's going to connect to a streaming endpoint.
So for that purpose, what I'm going to do, I'm going to create another endpoint over here and this
endpoint is going to be named as So I'm going to change this one.
The value is going to be slash stream and then producers is going to be media type dot and Json value.
So application and Json value and this function name is going to be.
So this is not going to connect to the reviews, this is just going to connect to the movie info.
So I'm going to name this one as retrieve movie info and there is not going to be any path variable
or something like that.
So let's go ahead and remove that and this code is going to be a little bit different.
So what we are going to do, we are going to build a new client, right?
So in that case it's going to be movies info rest client dot retrieve movie info stream.
So this function is not available at in the client.
We'll go ahead and create that.
There you go.
So this function is created over here.
So the very first thing is this function needs to connect to a particular endpoint.
So if you go ahead and open our movies info service.
So here is a controller.
So in the controller, the endpoint that we are going to connect is slash movie infos slash stream.
So that's the endpoint we are going to connect.
So the very first thing is we are going to build the URL.
Now let's go to the function and then paste it over here and the endpoint is going to be slash stream,
right?
So now if we go and take a look at the movies info controller over here, so the endpoint is basically
stream.
And then if you go and take a look at the movies info URL and if you open the application dot yaml file
in the movie service, you can notice that the endpoint that we have here is http colon slash slash
localhost 80, 80 slash v1 slash movie infos and then we are just appending the stream to it right now.
The next step is we are going to be using the same code and then we will do a little bit of tweaks over
there and then put it over here.
And this function is going to be not taking any movie ID, Let's go ahead and remove that and then we
don't even want this not found handler over here.
We can remove that one too.
And one another thing is that this function is going to return a flux, right?
It's going to be body of flux, which means we are going to use the body to flux function and then we
need to change the same thing over here to it's going to be a flux of movie info, not movie anymore.
It's going to be a flux of movie info.
Now let's go back to the movie's controller and then see what needs to be fixed.
So in here, this function is going to be returning you a flux of movie info.
Let's go ahead and change that.
As you can see right now, this function is returning you a flux of movie info.
So now we have our streaming endpoint in the movie service that's going to connect another streaming
endpoint in the movies info service.
Now let's go ahead and quickly test that.
So for this purpose, the first thing is we need to bring the movie info service application.
Let's bring that up because that's really important because the movie service is interacting with the
movies info service.
And now the next thing is we are going to be bringing up the movies service application.
There we go.
We have both the services up and running.
Now.
The next thing is we are going to connect to the streaming endpoint that we had just built, the movies
service.
So what we are going to do, we are going to go to the Curl commands.
That's part of the movie service and let's create a new client, which is slash movies, slash stream,
let's copy that and then let's go to the terminal and then connect to it.
So as soon as you connect to it, you can see that it is waiting for data.
Now what we are going to do is that we are going to create a movie info using this Curl command and
see whether the data is being pushed to this endpoint or not.
So I'm on the first terminal.
I'm going to connect to the movie info service using this Curl command and then create a movie.
There you go.
So I created a movie info.
Now the expectation is that the Curl command that's running in this terminal would have received it.
There you go.
So we have this movie info being received in the movies service that's been published to the streaming
endpoint and the streaming endpoint that we had built in the movie service is able to receive it.
And the way it works is by using the web client.
So the movies info controller is connecting to this retrieve movies info stream function, and this
function is a streaming endpoint client for the movies info service.
So as a whole, we have a microservice which is streaming on another service through web client.
When you are building applications using microservice architecture, these kind of use cases are pretty
common.
So if you have a use case where you want to build a client for a streaming endpoint, then you can use
web client for that purpose.
I hope you all were able to successfully implement this in your machine.
If you have any questions, please raise it in Q&A.
I would be happy to help.
This marks the end of this lecture.
Thank you for watching.