Skip to main content

Zuul Edge Server

Zuul to Proxy your Microservices

A common challenge when building microservices is providing a unified interface to the consumers of your system. The fact that your services are split into small composable appsshouldn’t be visible to users or result in substantial development effort.
To solve this problem, Netflix created and open-sourced its Zuul proxy server. Zuul is an edge service that proxies requests to multiple backing services. It is “front door” to your system, which allows a browser, mobile app, or other user interface to consume services from multiple hosts without managing cross-origin resource sharing (CORS) and authentication for each one.

Spring Cloud has created an embedded Zuul proxy to ease the development of a very common use case where a UI application wants to proxy calls to one or more back end services. This feature is useful for a user interface to proxy to the backend services it requires, avoiding the need to manage CORS and authentication concerns independently for all the backends.
To enable it, annotate a Spring Boot main class with @EnableZuulProxy, and this forwards local calls to the appropriate service based on configuration defined in config files. For e.g /api/authservice/… request is forwarded to auth-service.
Zuul has different types of filters that enables us to quickly apply functionality to our edge service. These filters help us perform the following functions:
  • Authentication and Security.
  • Insights and Monitoring.
  • Dynamic Routing.
  • Stress Testing.
  • Load Shedding.
  • Static Response handling.
In our example we have defined routing rules (based of URL it forwards request to client-service), filter for logging request url, method and time of request.
We will be referring to two application which we have posted on different application.

Java Code:

Config class annotated with @EnableZuulProxy

Logging filter

Config for Zuul routing rules & eureka service discovery. In config we have defined prefix as /api, routes for authclientservice.

In post Ribbon, Hysterix using spring feign we have defined authclientservice using ribbon and hysterix, which communicates to authservice service application.

We have prefix url as “/api”, then “/authclientservice” for authclientservice service application.
RESTful endpoint for authentication defined in authclientservice application is “/auth/login/authenticate”. Now for end client to access authentication end-point through endge-server will be “/api/authclientservice/auth/login/authenicate.

Start application

Application will get started at 6061 port.
Use below curl commands for authentication.

Request getting logged using ZuulFilter which we have defined.

Request routed to authclientservice application

And at last request is served by authservice application.

Cheers – Happy learning 🙂
Ketan Gote


Popular posts from this blog

Redis Basic CRUD

We have seen how to setup on your linux machine here , now we will see how to perform basic CRUD operations using Spring Data & Redis server We will be creating a simple application that would persist an employee information into redis database. You will be needing certain JARs like jedis.jar, spring-data-redis.jar etc details of which you can download and view at  First of all we will be creating the Employee entity, plz note that we are using the Serializable interface which automatically mapps the objects against the key. import ; public class Employee implements Serializable { private static final long serialVersionUID = - 8243145429438016231L ; public enum Gender { Male , Female } private String id; private String name; private Gender gender; private int age; public String getId () { return id; } public void setId ( String

Eureka-Server with spring cloud netflix

In this write-up we will focus on Service Registry – Eureka Server Rest service (auth-service application, eureka client) which register itself to registry. Web application which consumes Rest service using service registry. Service discovery  allows services to find and communicate with each other without hardcoding hostname and port. Eureka Server In spring-boot application enable the Eureka-Server by adding @EnableEurekaServer annotation to spring boot application. We have put all the configuration on GIT and this is accessed using config-server. To now more about centralized configuration (config-server) click  here eurekaserver.yml Place below bootstrap.yml in application, it basically connects to config-server and gets it required configuration. Start the spring-boot application and access eureka server using http://localhost:8760/ you will get below screen. Right now there is no application which is registered to e

Redis Installation Steps

“ Redis is an in-memory key-value store known for its flexibility, performance, and wide language support” Inorder to install redis on your machine you need ubuntu 16.4 and a non-root user with sudo privileges to perform the administrative functions required for this process. Download and Extract the Source Code Create a tmp directory cd /tmp Download the latest stable version of Redis curl -O untar tar xzvf redis-stable.tar.gz Move into the Redis source directory structure that was just extracted cd redis-stable Build and Install Redis Now, we can compile the Redis binaries by typing make After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do this by typing: make test This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing: sudo