Spring Boot Application With Zull API Gateway
Posted By : Deepak Maurya | 10-Sep-2020
Zuul server is an API Gateway application. It handles all the requests and performs the dynamic routing of microservice applications.All Netflix traffic first goes to a Zuul cluster which is mainly responsible for dynamic routing, monitoring, resiliency and security based on different filters.
Zull Filters
There are four types of filters in Zull that enable us to intercept the traffic. We can add any number of custom filters for a particular url pattern.
Pre filters – Pre filters are invoked before the request is routed.
Post filters –Post filters are invoked after the request has been routed.
Route filters –Route filters are used to route the request.
Error filters – Error filters are invoked when an error occurs while handling the request.
Add Maven Dependecy
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
Adding Main Class in ApiGateWay Service (Zull Application)
@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
public class ApiGateWay {
public static void main(String[] args) {
SpringApplication.run(ApiGateWay.class, args);
}
}
@EnableZuulProxy annotation is used to make your Spring Boot application act as a Zuul Proxy server.
@EnableEurekaClient makes this application an Eureka client, so that it can interact with the service registry and obtain the required information .
Configuration for Application.properties file.
server.port = 7000
eureka.client.serviceUrl.defaultZone = http://localhost:8761/eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
zuul.routes.courseservice.path=/user-service/**
zuul.routes.courseservice.serviceId=user-service
These are the two most important properties which enable Zuul to perform request routing.
zuul.routes.courseservice.path=/user-service/**
zuul.routes.courseservice.serviceId=user-service
If a request comes to the /user-service/* URL path, that request will be directed to the service registered with service-id user-service.
Testing The Application
http://localhost:7000/user-service/api/v1/user/details
We, at Oodles Technologies, provide full-scale SaaS app development services to build scalable, responsive, and quality-driven web and mobile applications. Contact us for technical assistance or drop us a line at [email protected] for more detail.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Deepak Maurya
Deepak is a backend developer and has knowledge of Java and Android. His hobbies are travelling and playing cricket.