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
€66.35
List Price:  €94.79
You save:  €28.44
£55.27
List Price:  £78.97
You save:  £23.69
CA$97.91
List Price:  CA$139.89
You save:  CA$41.97
A$107.61
List Price:  A$153.73
You save:  A$46.12
S$94.02
List Price:  S$134.32
You save:  S$40.30
HK$544.76
List Price:  HK$778.26
You save:  HK$233.50
CHF 61.99
List Price:  CHF 88.57
You save:  CHF 26.57
NOK kr773.52
List Price:  NOK kr1,105.08
You save:  NOK kr331.55
DKK kr494.87
List Price:  DKK kr706.99
You save:  DKK kr212.12
NZ$119.04
List Price:  NZ$170.06
You save:  NZ$51.02
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,334.01
List Price:  ৳11,906.24
You save:  ৳3,572.23
₹5,905.12
List Price:  ₹8,436.24
You save:  ₹2,531.12
RM312.96
List Price:  RM447.10
You save:  RM134.14
₦117,219.95
List Price:  ₦167,464.25
You save:  ₦50,244.30
₨19,380.58
List Price:  ₨27,687.73
You save:  ₨8,307.15
฿2,429.14
List Price:  ฿3,470.35
You save:  ฿1,041.21
₺2,412.08
List Price:  ₺3,445.98
You save:  ₺1,033.89
B$405.06
List Price:  B$578.68
You save:  B$173.62
R1,267.31
List Price:  R1,810.53
You save:  R543.21
Лв129.73
List Price:  Лв185.34
You save:  Лв55.60
₩97,779.80
List Price:  ₩139,691.42
You save:  ₩41,911.61
₪261.55
List Price:  ₪373.67
You save:  ₪112.11
₱4,130.77
List Price:  ₱5,901.36
You save:  ₱1,770.58
¥10,901.93
List Price:  ¥15,574.86
You save:  ¥4,672.92
MX$1,414.26
List Price:  MX$2,020.46
You save:  MX$606.19
QR254.33
List Price:  QR363.35
You save:  QR109.01
P948.83
List Price:  P1,355.53
You save:  P406.70
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,478.50
List Price:  E£4,969.50
You save:  E£1,491
ብር8,583.46
List Price:  ብር12,262.61
You save:  ብር3,679.15
Kz63,877.12
List Price:  Kz91,256.94
You save:  Kz27,379.82
CLP$67,980.58
List Price:  CLP$97,119.28
You save:  CLP$29,138.70
CN¥507.18
List Price:  CN¥724.58
You save:  CN¥217.39
RD$4,200.06
List Price:  RD$6,000.34
You save:  RD$1,800.28
DA9,338.81
List Price:  DA13,341.73
You save:  DA4,002.91
FJ$158.92
List Price:  FJ$227.04
You save:  FJ$68.12
Q538.38
List Price:  Q769.16
You save:  Q230.77
GY$14,583.53
List Price:  GY$20,834.51
You save:  GY$6,250.97
ISK kr9,640.42
List Price:  ISK kr13,772.62
You save:  ISK kr4,132.20
DH696.78
List Price:  DH995.44
You save:  DH298.66
L1,273.82
List Price:  L1,819.82
You save:  L546
ден4,077.60
List Price:  ден5,825.40
You save:  ден1,747.79
MOP$559.09
List Price:  MOP$798.74
You save:  MOP$239.64
N$1,260.89
List Price:  N$1,801.35
You save:  N$540.46
C$2,566.52
List Price:  C$3,666.61
You save:  C$1,100.09
रु9,423.16
List Price:  रु13,462.23
You save:  रु4,039.07
S/264.65
List Price:  S/378.10
You save:  S/113.44
K280.62
List Price:  K400.90
You save:  K120.28
SAR262.75
List Price:  SAR375.38
You save:  SAR112.62
ZK1,926.57
List Price:  ZK2,752.36
You save:  ZK825.79
L330.17
List Price:  L471.69
You save:  L141.52
Kč1,676.98
List Price:  Kč2,395.79
You save:  Kč718.80
Ft27,187.34
List Price:  Ft38,840.72
You save:  Ft11,653.38
SEK kr769.78
List Price:  SEK kr1,099.74
You save:  SEK kr329.95
ARS$70,112.88
List Price:  ARS$100,165.56
You save:  ARS$30,052.67
Bs483.65
List Price:  Bs690.96
You save:  Bs207.30
COP$308,470.35
List Price:  COP$440,690.82
You save:  COP$132,220.46
₡35,450.59
List Price:  ₡50,645.88
You save:  ₡15,195.28
L1,762.11
List Price:  L2,517.41
You save:  L755.29
₲543,153.02
List Price:  ₲775,966.15
You save:  ₲232,813.12
$U2,992.07
List Price:  $U4,274.58
You save:  $U1,282.50
zł287.83
List Price:  zł411.21
You save:  zł123.37
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.