This project demonstrates spring-cloud- Netflix-zuul gateway service with routing filters
run mvn clean install
Zuul acts as an API gateway or Edge service,the Zuul is built to enable dynamic routing, monitoring, resiliency, and security.
It provides a range of different types of filters,
- pre filters – are invoked before the request is routed.
- post filters – are invoked after the request has been routed.
- route filters – are used to route the request.
- error filters – are invoked when an error occurs while handling the request.
We can implement these filters by extending a class ZuulFilter, I have implemented a sample filter to add location in the request header (AddRequestHeaderFilter class)
- [optional] To check the service getting registered with service discovery, we need to run the service discovery on our machine, You can find project in my repo eureka-service-discovery
- Step 1: Launch the service discovery
- Step 2: Add @EnableZuulProxy annotation on Main class to enable the Zuul proxy
- Step 3: We need to run some client apps to see routing through proxy ( hello application and goodbye application ) , launch them
- Step 4: Zuul by default uses application name for routing
For example: If gateway service is running on port 8080 and hello application running on 1111 and goodbye application running on 2222 port
You can hit the hello and goodbye application end points on port 8080 only (hello and goodbye applications end points can be accessed using http://localhost:8080/hello and http://localhost:8080/goodbve) . The user need not to know the exact port on which hello and goodbye applications are running, the proxy or gateway service is managing this routing in the background
- Step 5: You can find the location is getting in the request header which is coming from zuul proxy.
Happy Coding!!
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Eureka Discovery Client
- Spring Boot Actuator
- Spring Web
- Zuul [Maintenance]
The following guides illustrate how to use some features concretely:
- Service Registration and Discovery with Eureka and Spring Cloud
- Building a RESTful Web Service with Spring Boot Actuator
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
- Routing and Filtering
The dependencies listed below are in maintenance mode. We do not recommend adding them to new projects:
- Zuul
The decision to move most of the Spring Cloud Netflix projects to maintenance mode was a response to Netflix not continuing maintenance of many of the libraries that we provided support for.
Please see this blog entry for more information on maintenance mode and a list of suggested replacements for those libraries.