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 info@oodlestechnologies.com for more detail. 

About Author

Author Image
Deepak Maurya

Deepak is a backend developer and has knowledge of Java and Android. His hobbies are travelling and playing cricket.

Request for Proposal

Name is required

Comment is required

Sending message..