Monday, September 09, 2019

Spring Zuul Server

Zuul Server is provided by Spring framework to proxy your request url. It handles all the requests and does the dynamic routing of microservice applications. The Zuul Server is also known as Edge Server.
For Example, your url having this pattern /api/login is mapped to the login service and /api/user is mapped to the user service and Zuul Server dynamically routes the requests.
Lets first create a Zuul server
Iamge1
Image2Image3Image4Image5

Have below given entries in your application.properties
spring.application.name = zuulserver
zuul.routes.json.path = /todo/**
zuul.routes.json.url = https://jsonplaceholder.typicode.com/todos/
server.port = 8111
Image6
Lets try to understand what each entry is saying
'- spring.application.name define the name of the Zuul sever
'- zuul.routes.products.path specify the url that will be maped for rounting
'- zuul.routes.products.url configure the original url that is going to be hit for taking the data
'- server.port port on which zuul sever is going to listen.
Now lets compile the maven application and create a spring boot jar and run the same using below command
java -jar siddhu-zuul-example-server-0.0.1-SNAPSHOT.jar
Image7Image8
If you see above the original URL which is hit to get the data is https://jsonplaceholder.typicode.com/todos/ but the url that we hit on the broswer is http://localhost:8111/todo/3.
Zuul it self will take care of proxing the url and redirecting to perticular server.

No comments: