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.
Dependencies
















Application.properties









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

Comments

Popular posts from this blog

Centralized configuration using Spring Cloud Config

In this blog we will be focusing on centralized configuration using  Spring Cloud Config  project. For single standalone application we can keep all required configuration bundle with application itself.  However, when we have more than one application, say in a microservice architecture, a better alternative would be to manage the configurations centrally. With the Config Server we have a central place to manage external properties for applications with support for different environments. Configuration files in several formats like YAML or properties are added to a Git repository. Features Spring Cloud Config Server features: HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content) Encrypt and decrypt property values (symmetric or asymmetric) Embeddable easily in a Spring Boot application using  @EnableConfigServer Config Client features (for Spring applications): Bind to the Config Server and initialize...

Function Point Analysis : ISO/IEC 20926:2009

This blog focuses on explaining the Function Point calculations. Software Sizing Background Function Point Rules for Counting FP Deep Dive - Function Point Analysis Case Study General Software Characteristics Details History - Measurement Methodologies Lines of Code (Oldest) Use case based Software Sizing IPFUG Function Point Analysis (ISO) Need for Software Sizing. Estimation and Budgeting Phasing Development Work Prioritization of Work Monitoring the Progress Bidding for Projects Allocating Testing Resources To measure and Manage Productivity Risk Assessment Software Asset Valuation CMMi Level 2 and 3 require that a valid sizing method be used. Software Sizing - Lines of Code The easiest and historically the most common method in Sizing Software project has been counting the number of lines of code and / or the number of screens. Advantages Automation of the counting process can be done Intuitive as the measurements are easily u...

CRUD in MongoDB & Spring Data

Now, since we have already been introduced to mongo and its server is setup. We shall now move on to performing basic CRUD operations. Lets take a use case example of ‘Company’ database that stores employee information.  We wish to store employee name, email address, age and multiple addresses. Traditionally in RDBMS we would create an Employee table and Address Table having foreign key reference to ‘employee id ‘ Incase of NoSQL, we will be creating Employee documnet which will have store employee information like name, email, age and an array of employes address. Following is a snippet of the schema defined { "name" : "", "email" : "", "age" : “”, "address" : [ ... ] } Thus to begin with, we will first define the entities. We have employee as an aggregate root entity that stores list of address having 1-M relatioship. Address Entity is represend as @Embeddable as it is embaded in another aggregate root entity. Employee is...