Design a Service Gateway Using Zuul Reverse Proxy

Go Back to Course Outline Continuing on, Zuul is a router and a server-side load balancer developed and popularized by Netflix. Zu...

Go Back to Course Outline

Continuing on, Zuul is a router and a server-side load balancer developed and popularized by Netflix. Zuul uses ribbon to call the remote services registered in a discovery server such as Eureka. By annotating a SpringBoot class with @EnableZuulProxy, a route is created for each service from the discovery client. As we add new services, routes are refreshed.

@EnableZuulProxy also enables 2 additional endpoints:
  • Routes - a get to this endpoint returns a list of map routes, to get more details, add the query param format=details
  • Filters - a get to this endpoint returns a map of Zuul filters
Creating a Zuul Enabled project
  1. Create a new SpringBoot and add the following dependencies
    1. spring-cloud-starter-netflix-zuul
    2. spring-cloud-starter-netflix-eureka-client - register this server to the service discovery
    3. spring-boot-starter-web and spring-boot-starter-actuator to expose server information
  2. Annotate the SpringBoot class with @EnableZuulProxy and @EnableDiscoveryClient.
  3. Configuration the application name, port, eureka instance and Zuul in the property file.
No change is needed in our catalog service.

Run the projects in the following order
  • Terawarehouse-config-server
  • Terawarehouse-service-discovery
  • Terawarehouse-load-balancer
  • Terawarehouse-catalog 
The following url should be accessible:
  • <network_ip>:8000/catalog/default</network_ip>
  • <network_ip>:8761</network_ip>
  • <network_ip>:8001/api/v1/categories</network_ip>
  • <network_ip>:8762/routes</network_ip>
  • <network_ip>:8762/filters</network_ip>
  • <network_ip>:8762/catalog/api/v1/categories</network_ip>
The last entry routes our request in the /catalog/** path to the catalog service without knowing it’s actual url and port. And that’s the beauty of Eureka with Zuul, it simplifies the adding of a new service. Take note that we can run more than 1 instance of each service without changing the configuration. And that is what we will try to do next.

And that concludes this video. I hope this information will be of use to you when you decided to develop your own project using the microservice architecture.

I would appreciate if you could subscribe to my channel to get notified when I upload the next video and that will validate that what I’m doing is helpful for others, which will definitely inspire me to share more technical videos.


spring-microservice 283720278755759702

Post a Comment Default Comments


Are you looking for freelancers in the Philippines? Get in touch.


If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.