09. Working with Zuul API Gateway

25 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.59
List Price:  €93.70
You save:  €28.11
£56.03
List Price:  £80.05
You save:  £24.01
CA$96.39
List Price:  CA$137.71
You save:  CA$41.31
A$107.98
List Price:  A$154.26
You save:  A$46.28
S$95.50
List Price:  S$136.44
You save:  S$40.93
HK$547.57
List Price:  HK$782.28
You save:  HK$234.70
CHF 64.43
List Price:  CHF 92.05
You save:  CHF 27.61
NOK kr776.82
List Price:  NOK kr1,109.79
You save:  NOK kr332.97
DKK kr489.21
List Price:  DKK kr698.91
You save:  DKK kr209.69
NZ$118.81
List Price:  NZ$169.74
You save:  NZ$50.92
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,729.18
List Price:  ৳11,042.16
You save:  ৳3,312.97
₹5,842.93
List Price:  ₹8,347.41
You save:  ₹2,504.47
RM333.67
List Price:  RM476.70
You save:  RM143.02
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,599.98
List Price:  ₨28,001.17
You save:  ₨8,401.19
฿2,600.12
List Price:  ฿3,714.62
You save:  ฿1,114.50
₺2,271.31
List Price:  ₺3,244.87
You save:  ₺973.56
B$363.64
List Price:  B$519.51
You save:  B$155.87
R1,308.28
List Price:  R1,869.05
You save:  R560.77
Лв128.30
List Price:  Лв183.29
You save:  Лв54.99
₩96,996.60
List Price:  ₩138,572.52
You save:  ₩41,575.91
₪261.41
List Price:  ₪373.46
You save:  ₪112.04
₱4,045.59
List Price:  ₱5,779.67
You save:  ₱1,734.07
¥11,052.75
List Price:  ¥15,790.32
You save:  ¥4,737.57
MX$1,197.81
List Price:  MX$1,711.23
You save:  MX$513.42
QR257.31
List Price:  QR367.61
You save:  QR110.29
P1,000.11
List Price:  P1,428.79
You save:  P428.68
KSh9,335.98
List Price:  KSh13,337.69
You save:  KSh4,001.70
E£3,349.95
List Price:  E£4,785.86
You save:  E£1,435.90
ብር4,013.63
List Price:  ብር5,734.01
You save:  ብር1,720.37
Kz58,409.45
List Price:  Kz83,445.65
You save:  Kz25,036.20
CLP$67,298.07
List Price:  CLP$96,144.23
You save:  CLP$28,846.15
CN¥506.79
List Price:  CN¥724.02
You save:  CN¥217.23
RD$4,121.81
List Price:  RD$5,888.55
You save:  RD$1,766.74
DA9,423.87
List Price:  DA13,463.25
You save:  DA4,039.38
FJ$159.96
List Price:  FJ$228.52
You save:  FJ$68.56
Q547.38
List Price:  Q782
You save:  Q234.62
GY$14,742.16
List Price:  GY$21,061.13
You save:  GY$6,318.97
ISK kr9,832.89
List Price:  ISK kr14,047.59
You save:  ISK kr4,214.70
DH712.24
List Price:  DH1,017.53
You save:  DH305.29
L1,243.01
List Price:  L1,775.81
You save:  L532.79
ден4,046.68
List Price:  ден5,781.23
You save:  ден1,734.54
MOP$564.08
List Price:  MOP$805.87
You save:  MOP$241.78
N$1,315.96
List Price:  N$1,880.02
You save:  N$564.06
C$2,592.36
List Price:  C$3,703.54
You save:  C$1,111.17
रु9,349.94
List Price:  रु13,357.63
You save:  रु4,007.69
S/263.70
List Price:  S/376.73
You save:  S/113.03
K271.96
List Price:  K388.53
You save:  K116.57
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,886.12
List Price:  ZK2,694.57
You save:  ZK808.45
L326.39
List Price:  L466.29
You save:  L139.90
Kč1,650.20
List Price:  Kč2,357.53
You save:  Kč707.33
Ft25,629.21
List Price:  Ft36,614.73
You save:  Ft10,985.52
SEK kr770.71
List Price:  SEK kr1,101.06
You save:  SEK kr330.35
ARS$61,698.11
List Price:  ARS$88,143.94
You save:  ARS$26,445.82
Bs486.86
List Price:  Bs695.54
You save:  Bs208.68
COP$271,471.23
List Price:  COP$387,832.67
You save:  COP$116,361.43
₡35,819.54
List Price:  ₡51,172.97
You save:  ₡15,353.42
L1,740.31
List Price:  L2,486.27
You save:  L745.95
₲526,285.13
List Price:  ₲751,868.13
You save:  ₲225,582.99
$U2,699.91
List Price:  $U3,857.19
You save:  $U1,157.27
zł284.80
List Price:  zł406.88
You save:  zł122.07
Already have an account? Log In

Transcript

Session, let us learn about Zul API gateway. This is a part of Netflix OSS package. It integrates very well with Eureka. The Zoom API gateway is a front door for all the requests which are trying to access the Microsoft Visual COBOL. Let me explain this with a pictorial representation. Here.

You may What are these? These are our micro services, they are nothing but RESTful API. All these micro services get themselves registered to Eureka server. So this will see registry in the previous session, what actually we have seen is we have created a web application and we tried to access the micro service that is what we have done. So this client is nothing but a web application, which is trying to access the micro service. But we are going to introduce a gateway This is going to act as a front door for all the requests that are coming from the outside world.

But this part is the outside work. This is the micro service ecosystem. They have done the request that is coming in from the client. This zone API gateway will send the request to the appropriate services, how it will work, what is the name of the service, it is gone query in the registry. I hope this picture in the presentation is very clear. In the previous case, your client was accessing the service directly, it means you are exporting all the micro services with their port number and the URL.

But in this case, there is a security it's kind of a gate, Zul API gateway, which will invoke all the requests that is coming in from the client. Based on the client input. It is going to query your records you see and gilded by appropriate micro service back to the client pool API. Also have got few standard filters, you know what is the use of a filter, whenever a request comes in, you want to authenticate the request, there is an authentication, you will be filtering the request and sending it to the back end service. Same thing can be achieved with the help of Zul API gateway. So, we will talk about filters in the next session.

Now, in this particular session, what actually we are going to do with already we are about to micro service, we are what our application we will introduce a service that is we are going to create a service which is going to add a Zul proxy, whenever a client request is coming in based on the request, it is going to connect it to the appropriate service. Let me first show you the pictorial representation of what actually we are going to do and then we will start working on it. So here already you have order service. And you have booked service car stops to our auto service connects to book service where the services are registered to Eureka server. Right. So there's already you know, and we created a web client, because something but that web application that was created using spring boots.

Now, this web client is not going to access order service directly. Instead, you're going to have the Zul API gateway, my web client this time I'm going to give the name of Zul web client to going to be Zul proxy, are we allowed to Zul gateway so the client will make a call to this particular Zul gateway official using this template. This rule APA is going to query the Eureka server based on the client's request. It is going to connect to order service or service. Already we have created hotel service also it is it is registered to you cross over. So I will show you how to access these services using Zul API gateway.

Now let me go back to eclipse. We are in Eclipse. Already we have got the micro services ready book service order service portal service. Together with that I have got the Eureka server also, what's next we need a client, the client which is going to access Zul API gateway. So for whom API gateways we have to create a application. So first let us create an application from Zul gateway, go to File, New spring starter project, let me give the application name of Zul gateway, and the description of creating Zul proxy.

Click Next. Now here I need to search for Zul Can you see cloud routing? What is the meaning of it? Whatever request is coming in, that is taken by API gateway and it will route it to the appropriate micro service. This rule has got few advantages and features also that we will be talking while we are doing filters. Let me click next and click Finish.

The application is created. Let me open it lol gateway application. Java, this class should be annotated with our direct enable Zul proxy. Let me add annotation. Now this class is ready. What makes I don't need a controller.

This is not going to ask us a complete micro service. This is basically a gateway for the client to access a micro service. So we need certain configuration details that has the routing details which will be used by the client. The client will call only these who will get a PA the Zul gateway AP is responsible for this particular application is responsible To the backend micro services. So what we need to do, we have to create an YAML file, we need to specify the port number as usual Give a name for the service, so that it can register itself to Eureka and then we have to give the routing details. So let me create this our copy application dot YAML from some other application.

So here I have got application dot Yama, let me give a different port number 9000. The application name is Zul service, and then our client service URL here I'm getting a warning Why? Because we are adding only this rule dependency to this application. This application also register itself also automatically will register itself to your a car registry. So we need that dependency to be added. So let me open book service POM dot XML, we need to add the Spring Cloud starter a car will copy this and then I'll come to the school.

Gateway here, POM dot XML file added controllers. Now I'll come back to this application dot Yama. Now the error is gone, what makes Next we are going to provide the route. So, let me explain this it is going to be Zoo dot route dot the application name, which application actually you want to access, whether you want to access portal service or you want to access order service or you want to access good book service. So, that information you have to given the rope Zul dot route dot name, the application name, this is what we are going to give Now, let me explain it with a simple example. And then we will start adding on top of it.

So already we are having our order service which is working perfectly fine. The name of the application is what order service so it has to be google.com Got order with order for recent capital. So let me add that it has to be like let me just press Enter Enter public and understand this. This whole gateway is trying to do routes for different applications. To start with I'm using order service, I need to specify the path and the URL, I can do the path and the service ID. Let me show you how this can be done order service right.

So here path colon space slash order slash stop. I will explain this and again, you are an RA you can just give the service ID service ID What is the name again in the order service only. Let me explain this. Basically, you are trying to give different routing detail for different micro services. It is dot route dot application name, in my case I have used order service. If you want to access portal service you need to do voter service, the client is going to talk only to this particular application.

If he wants to access order service, he has to cause this application to Zul gateway using slash orders. By the way, you are not exporting the micro service directly to the client only using the rule gateway, this micro service is available to decline you are trying to make a intermediate layer or an abstraction so that the micro service is not exposed to these clients directly. Okay, I hope you can understand this I have given slash orders. So the client will be called using slash orders to access order service. In the previous scenario, we gave the complete URL of the order service only. In this case, we are not going to touch order service directly.

We are going to talk to this particular Zul gateway which will connect to the back end okay? This is that if you want to add a prefix that also you can do, let me show you how to do with that prefix slash APA. So, if I want if the client wants to ask without a service, what is the path or what is the URL that he has to give localhost colon 9000 slash JPA slash orders automatically the recorder service in RFM is what is a copy of our book slash offer whatever your work that you can give it. I mean in the URL, the complete URL, so client talks to Zoo zoo in turn talks to order service, how soon can talk order service, you are specifically given the service ID with the help of that it can connect order service directly. So this dual gateway, dual application is done.

So let me run it. Select dual gateway right flick runners Spring Boot app Let us run next, what else we need? We have got multiple micro services which are running Let me check what are the micro services which are running. Here I have got the order service running book service running dual gateway just now it is getting started. Eureka server is also running. If I want I can also run hotel service.

Let me check whether it is available hotel service. Yeah, here it is. I'm just trying to read relaunch. Okay, we'll close it. That is it is giving me an error. I'll minimize this console.

I will try to run portal service also I'll open it and I will run this portal for resources. Okay, so we have got order service running book service running water service running, Zul gateway running Eureka server. So your server will have all these services registered with itself. Let me just go and check it the browser, okay, there is some problem in which application Zul gateway Let me check what is the Euro rule gateway address already in US rule gateway which address 9000 Okay, so you can just see this within club running hotel service. Again I have clicked dual gateway that is why I got the address already in use. So I have to be very careful extra careful when selecting it.

Let me run portal service portal service Okay, now we'll go on the browser First we will check it out. So I'll open the registry Let me refresh. See, all the four services are shown. Now, we have not created a client I have created the application I will show you later. Let me open the Zul service 9000. Now it does open now I want to access order service order services in which port number 8087 and you know the flow.

So here we have given what is that search looks like. Search looks like that. just running it does wait oh let me refresh it again no jack price 900 book it 94 I have got it right I will come to this 9000 how to add the SATA service what is the You are a JPA flash order slash I have given double stack so it can go down the hierarchy So, it is slash books slash jack. Now say about the output, so using Zul gateway APA I'm trying to access order service. Similarly, if you want to access any other service, like hotel service or book service even directly you can do it over here. Let me just add it we are done for order service right.

So let me just do it for hotel service. It has to be application name, remember this. I need to give back and service ID so I Just copy it. And here I will add it over here. Either you can view the service ID or you can go in for the URL. If you are if you want to view the URL what actually you have to give the part where exactly the service is available.

So, okay, let me just go here. in Eureka, we have got total service and click this. It is at 81, the past 8081. Do that see here? Okay, this is our order service. If we want we can try with book service also.

So in the as of now to start with and trying to access to services. I will save this over here in Chicago, it has to be hotels, you can give any name, I'm trying to map it with the service name. That's it. Now, I will relaunch this application rule gateway. I think the application is started. I'll go back to the browser.

Now here's 9000 APS. Last orders we have given are now slash hotel slash all hotels. Okay, I hope you can understand what actually we are doing now as of now is using these old API gateways, we are trying to access these micro services, we are not calling the micro services directly. In fact, we are trying to call it with a path that we have specified this will be used by any web client. So, what we will do is we will try to create a web application and access these micro services from the web application. Okay, so, for that I have simply created a dual web client.

Can you see this SRC main java.com dot dual client dual web client application. Now, I will minimize some other things so that I can just show you directly, no web client application here. It extends services for Spring Boot. servlet initializer. Remember this this While creating a web application you need to select one only then you will be getting that servlet initializer okay and then I let me come to the controller in the controller, I have got two methods right. So, what I will do I just want to show you the output.

So, as of now, so, we have to give the URL what are the services we are trying to access we are we are trying to access order service and hotel service. So, let me add one more method already I have got two methods for accessing on order service. Let me add one more method to access the photo service also. Let me give the name of show hotels. Of course we have our two more methods in hotel service. You can try it that also.

And here. Show hotels method. I don't need any records. I just need model map. And now we have to frame the Ura So, how to find the Ura just localhost 9000 slash API slash orders slash search okay. And again in this case it is 9000 slash API slash order slash one book.

Basically, this is not a micro service, I have a micro service which is having the book details. This is a PA, which is going to connect to the backend micro service. And then what is the next one here 9000 slash hotels slash all hotels. And here this hotel list I will copy the previous application assets. That is why I'm having the book class but I have not copied the hotel pack. So let me just copy the hotel from hotel service.

So, where is my hotel service? I'll open it. src main comm dot hotel app dot model right? So I'll open this copy hotel and on Ctrl C come to the Zul client, controller yoga book can control me okay. So, here what actually got about four methods one method will take me to home dot JSP in on that day I have a form to search the books by author then I Oh God, I mean I can proceed further to retrieve the book book which I have ordered. Then finally I have got show hotels for sure hotels we need to create a URL.

So, I will go to Home dot JSP So, this is giving me some error Let me check it out. I have been put hotel Okay, done. Good. Okay, so this is completed SRC main web app, I have to copy those files. Let me just go to book web client. Here I have got it right so SRC main with that webinar.

I'm going to copy it Ctrl V. Inside web by enough we will find a JSP we don't have a seal right. So that is why it is giving an error. Again, copy, paste. All these are very smaller issues but if you forget your application will never copy it Ctrl C, then come to rule web client palm dot XML. Here I need to paste it here palm dot XML, scroll down, Shift Ctrl C Ctrl Shift Ctrl F in this is a web application so I'm having only weapon jst JCL Of course because I'm using JSP if you're using any other mean framework like velocity or timeless, you have to work accordingly. Now in final dot JSP Okay, sorry in home dot JSP.

I want to get the list of hotels here after the form. Let me just have a href equal to shoe hotels. And now and in final dot JSP. I'm having book dot title Okay. What I will do was for showing the list of photos Let me just create another view and copy paste it Ctrl C Ctrl V let me give the name of hotel details now GST in order details the JC what what I need this is not message this is hotel list hotel What do I have hotel dot i will check it out because multiple applications are running your there are chances that your application may have name city cuisine and hotel ID I don't want to say a hotel ID. So it is hotel dot name, hotel dot city and hotel.we don't need this order now.

Okay, here if you want he can just view but of course I'm not going to have form action are what we will do, we don't need the submit button as you can try it out later that okay, we are having get one hotel, you return one hotel if you want to book a table in that particular hotel, you can just continue with this application. This is done. Okay, now I have completed everything. Let me run this web Zul web client. This is a web application, how will you run right click run as run on server. Patients which are there.

Just run only Zul with client click Finish. Restart server. Let me just keep my fingers crossed. I don't know like whether it will get any error or everything will work perfectly fine. Because I've got a blank page. I've got home dot JSP.

Right. So with client Let me check it out as to be hotel details dot JSP. Okay, hopefully it is okay. What I forgot I forgot to add application dot html. So let me copy it. From webclient there in the SRC main resources, application, curry application dot properties, and just copying it in Zul web client, SRC main sources Control V. There is no change in this because it's only the viewport Prefix and Suffix.

Okay, this added it, we save it, I will rerun the application go with client, restart server. But I have got the application. Okay, this is just a web application that we have done in the previous case. Let me select I mean, let me type jack. Click Search. Excellent.

It's working perfectly fine. As of now in this case, Zul web client is connecting to Zul proxy that is that Zul gateway, Zul gateway is connecting to the back end order service or a service is connecting to book service and retrieving that list. Okay, so from book service, back to our service, back to school gateways back to the client. That's what we got. So let me click order now. Good excellent it's working perfectly fine and again Now we will try with hotel service also let me click Show hotels oh my god there is some error in the spot Let me check it out show hotels fool client controllers okay here we are changed just now right.

So that is the problem all hotels has to return a list of hotels or the You are a song It has to be APA slash hotel slash all hotels and save it I will read an application. So these things remember this your APA Ura should be correct check whether you are annotating with at the rate controller as controller accordingly or to create the properties file REM and file. Now let me select Show hotels. I am not getting the list of hotels. Okay once again, in jewel climb controller. It is hotel list only.

If we try printing it here. Now I will rerun the application application has started let me click Show hotels. Oh my god Oh it's coming here can you see it's printing here in this place that is in the application itself it is printing it's coming to the controller soul client controller is coming it is hotel details dot JSP and open it okay we will print try printing this year also control the controllers oh my god sorry see the error display I have gone with a proper convention. So here it is hotel details I have given it as the capital here and the file name is lowercase D Okay. Let me rerun it again. In a started let me make sure for now I have got the output already we are printing I mean slash in dollar.

We are using expression language to print it that's why I'm getting it twice. I'm totally control this. So This is CL let us learn about filters. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.